aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/Objects/memoryobject.c
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2024-10-27 10:52:33 +0300
committershadchin <shadchin@yandex-team.com>2024-10-27 11:03:47 +0300
commit1529383373617c6d14ad4972afdc46a5eb35f954 (patch)
tree229b7647fafadd4ee4b93d20e606c534ad697365 /contrib/tools/python3/Objects/memoryobject.c
parent41d598c624442bf6918407466dac3316b8277347 (diff)
downloadydb-1529383373617c6d14ad4972afdc46a5eb35f954.tar.gz
Update Python 3 to 3.12.7
commit_hash:052a122399d67f1ea5dfbc5f6457e3e06200becf
Diffstat (limited to 'contrib/tools/python3/Objects/memoryobject.c')
-rw-r--r--contrib/tools/python3/Objects/memoryobject.c55
1 files changed, 27 insertions, 28 deletions
diff --git a/contrib/tools/python3/Objects/memoryobject.c b/contrib/tools/python3/Objects/memoryobject.c
index 3c88859acc..26871612ea 100644
--- a/contrib/tools/python3/Objects/memoryobject.c
+++ b/contrib/tools/python3/Objects/memoryobject.c
@@ -108,8 +108,6 @@ mbuf_release(_PyManagedBufferObject *self)
if (self->flags&_Py_MANAGED_BUFFER_RELEASED)
return;
- /* NOTE: at this point self->exports can still be > 0 if this function
- is called from mbuf_clear() to break up a reference cycle. */
self->flags |= _Py_MANAGED_BUFFER_RELEASED;
/* PyBuffer_Release() decrements master->obj and sets it to NULL. */
@@ -1092,32 +1090,19 @@ PyBuffer_ToContiguous(void *buf, const Py_buffer *src, Py_ssize_t len, char orde
/* Inform the managed buffer that this particular memoryview will not access
the underlying buffer again. If no other memoryviews are registered with
the managed buffer, the underlying buffer is released instantly and
- marked as inaccessible for both the memoryview and the managed buffer.
-
- This function fails if the memoryview itself has exported buffers. */
-static int
+ marked as inaccessible for both the memoryview and the managed buffer. */
+static void
_memory_release(PyMemoryViewObject *self)
{
+ assert(self->exports == 0);
if (self->flags & _Py_MEMORYVIEW_RELEASED)
- return 0;
+ return;
- if (self->exports == 0) {
- self->flags |= _Py_MEMORYVIEW_RELEASED;
- assert(self->mbuf->exports > 0);
- if (--self->mbuf->exports == 0)
- mbuf_release(self->mbuf);
- return 0;
+ self->flags |= _Py_MEMORYVIEW_RELEASED;
+ assert(self->mbuf->exports > 0);
+ if (--self->mbuf->exports == 0) {
+ mbuf_release(self->mbuf);
}
- if (self->exports > 0) {
- PyErr_Format(PyExc_BufferError,
- "memoryview has %zd exported buffer%s", self->exports,
- self->exports==1 ? "" : "s");
- return -1;
- }
-
- PyErr_SetString(PyExc_SystemError,
- "_memory_release(): negative export count");
- return -1;
}
/*[clinic input]
@@ -1130,9 +1115,21 @@ static PyObject *
memoryview_release_impl(PyMemoryViewObject *self)
/*[clinic end generated code: output=d0b7e3ba95b7fcb9 input=bc71d1d51f4a52f0]*/
{
- if (_memory_release(self) < 0)
+ if (self->exports == 0) {
+ _memory_release(self);
+ Py_RETURN_NONE;
+ }
+
+ if (self->exports > 0) {
+ PyErr_Format(PyExc_BufferError,
+ "memoryview has %zd exported buffer%s", self->exports,
+ self->exports==1 ? "" : "s");
return NULL;
- Py_RETURN_NONE;
+ }
+
+ PyErr_SetString(PyExc_SystemError,
+ "memoryview: negative export count");
+ return NULL;
}
static void
@@ -1140,7 +1137,7 @@ memory_dealloc(PyMemoryViewObject *self)
{
assert(self->exports == 0);
_PyObject_GC_UNTRACK(self);
- (void)_memory_release(self);
+ _memory_release(self);
Py_CLEAR(self->mbuf);
if (self->weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject *) self);
@@ -1157,8 +1154,10 @@ memory_traverse(PyMemoryViewObject *self, visitproc visit, void *arg)
static int
memory_clear(PyMemoryViewObject *self)
{
- (void)_memory_release(self);
- Py_CLEAR(self->mbuf);
+ if (self->exports == 0) {
+ _memory_release(self);
+ Py_CLEAR(self->mbuf);
+ }
return 0;
}