File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -2504,7 +2504,11 @@ static PyObject *
25042504bytearray_alloc (PyObject * op , PyObject * Py_UNUSED (ignored ))
25052505{
25062506 PyByteArrayObject * self = _PyByteArray_CAST (op );
2507- return PyLong_FromSsize_t (FT_ATOMIC_LOAD_SSIZE_RELAXED (self -> ob_alloc ));
2507+ Py_ssize_t alloc = FT_ATOMIC_LOAD_SSIZE_RELAXED (self -> ob_alloc );
2508+ if (alloc > 0 ) {
2509+ alloc += sizeof (PyBytesObject );
2510+ }
2511+ return PyLong_FromSsize_t (alloc );
25082512}
25092513
25102514/*[clinic input]
@@ -2700,8 +2704,13 @@ static PyObject *
27002704bytearray_sizeof_impl (PyByteArrayObject * self )
27012705/*[clinic end generated code: output=738abdd17951c427 input=e27320fd98a4bc5a]*/
27022706{
2703- size_t res = _PyObject_SIZE (Py_TYPE (self ));
2704- res += (size_t )FT_ATOMIC_LOAD_SSIZE_RELAXED (self -> ob_alloc ) * sizeof (char );
2707+ Py_ssize_t res = _PyObject_SIZE (Py_TYPE (self ));
2708+ Py_ssize_t alloc = FT_ATOMIC_LOAD_SSIZE_RELAXED (self -> ob_alloc ) * sizeof (char );
2709+ if (alloc > 0 ) {
2710+ res += sizeof (PyBytesObject );
2711+ res += alloc * sizeof (char );
2712+ }
2713+
27052714 return PyLong_FromSize_t (res );
27062715}
27072716
You can’t perform that action at this time.
0 commit comments