Skip to content

Commit 08759e1

Browse files
committed
Move unused_data and unconsumed_tail to PyGetSetDef
1 parent b219dcc commit 08759e1

1 file changed

Lines changed: 51 additions & 8 deletions

File tree

Modules/zlibmodule.c

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#endif
99

1010
#include "Python.h"
11-
#include "pycore_object.h" // _PyObject_XSetRefDelayed
11+
#include "pycore_pyatomic_ft_wrappers.h" // FT_ATOMIC_STORE_CHAR_RELAXED
1212

1313
#include "zlib.h"
1414
#include "stdbool.h"
@@ -837,7 +837,7 @@ save_unconsumed_input(compobject *self, Py_buffer *data, int err)
837837
if (new_unused_data == NULL) {
838838
return -1;
839839
}
840-
_PyObject_XSetRefDelayed(&self->unused_data, new_unused_data);
840+
Py_XSETREF(self->unused_data, new_unused_data);
841841
self->zst.avail_in = 0;
842842
}
843843
}
@@ -851,7 +851,7 @@ save_unconsumed_input(compobject *self, Py_buffer *data, int err)
851851
(char *)self->zst.next_in, left_size);
852852
if (new_data == NULL)
853853
return -1;
854-
_PyObject_XSetRefDelayed(&self->unconsumed_tail, new_data);
854+
Py_XSETREF(self->unconsumed_tail, new_data);
855855
}
856856

857857
return 0;
@@ -1628,7 +1628,7 @@ decompress(ZlibDecompressor *self, uint8_t *data,
16281628
if (unused_data == NULL) {
16291629
goto error;
16301630
}
1631-
_PyObject_XSetRefDelayed(&self->unused_data, unused_data);
1631+
Py_XSETREF(self->unused_data, unused_data);
16321632
}
16331633
}
16341634
else if (self->avail_in_real == 0) {
@@ -1809,10 +1809,36 @@ static PyMethodDef ZlibDecompressor_methods[] = {
18091809
{NULL}
18101810
};
18111811

1812+
static PyObject *
1813+
Decomp_unused_data_get(PyObject *op, void *Py_UNUSED(ignored))
1814+
{
1815+
compobject *self = _compobject_CAST(op);
1816+
PyMutex_Lock(&self->mutex);
1817+
assert(self->unused_data != NULL);
1818+
PyObject *result = Py_NewRef(self->unused_data);
1819+
PyMutex_Unlock(&self->mutex);
1820+
return result;
1821+
}
1822+
1823+
static PyObject *
1824+
Decomp_unconsumed_tail_get(PyObject *op, void *Py_UNUSED(ignored))
1825+
{
1826+
compobject *self = _compobject_CAST(op);
1827+
PyMutex_Lock(&self->mutex);
1828+
assert(self->unconsumed_tail != NULL);
1829+
PyObject *result = Py_NewRef(self->unconsumed_tail);
1830+
PyMutex_Unlock(&self->mutex);
1831+
return result;
1832+
}
1833+
1834+
static PyGetSetDef Decomp_getset[] = {
1835+
{"unused_data", Decomp_unused_data_get, NULL, NULL},
1836+
{"unconsumed_tail", Decomp_unconsumed_tail_get, NULL, NULL},
1837+
{NULL},
1838+
};
1839+
18121840
#define COMP_OFF(x) offsetof(compobject, x)
18131841
static PyMemberDef Decomp_members[] = {
1814-
{"unused_data", _Py_T_OBJECT, COMP_OFF(unused_data), Py_READONLY},
1815-
{"unconsumed_tail", _Py_T_OBJECT, COMP_OFF(unconsumed_tail), Py_READONLY},
18161842
{"eof", Py_T_BOOL, COMP_OFF(eof), Py_READONLY},
18171843
{NULL},
18181844
};
@@ -1826,11 +1852,26 @@ PyDoc_STRVAR(ZlibDecompressor_unused_data__doc__,
18261852
PyDoc_STRVAR(ZlibDecompressor_needs_input_doc,
18271853
"True if more input is needed before more decompressed data can be produced.");
18281854

1855+
static PyObject *
1856+
ZlibDecompressor_unused_data_get(PyObject *op, void *Py_UNUSED(ignored))
1857+
{
1858+
ZlibDecompressor *self = ZlibDecompressor_CAST(op);
1859+
PyMutex_Lock(&self->mutex);
1860+
assert(self->unused_data != NULL);
1861+
PyObject *result = Py_NewRef(self->unused_data);
1862+
PyMutex_Unlock(&self->mutex);
1863+
return result;
1864+
}
1865+
1866+
static PyGetSetDef ZlibDecompressor_getset[] = {
1867+
{"unused_data", ZlibDecompressor_unused_data_get, NULL,
1868+
ZlibDecompressor_unused_data__doc__},
1869+
{NULL},
1870+
};
1871+
18291872
static PyMemberDef ZlibDecompressor_members[] = {
18301873
{"eof", Py_T_BOOL, offsetof(ZlibDecompressor, eof),
18311874
Py_READONLY, ZlibDecompressor_eof__doc__},
1832-
{"unused_data", Py_T_OBJECT_EX, offsetof(ZlibDecompressor, unused_data),
1833-
Py_READONLY, ZlibDecompressor_unused_data__doc__},
18341875
{"needs_input", Py_T_BOOL, offsetof(ZlibDecompressor, needs_input), Py_READONLY,
18351876
ZlibDecompressor_needs_input_doc},
18361877
{NULL},
@@ -2056,6 +2097,7 @@ static PyType_Slot Decomptype_slots[] = {
20562097
{Py_tp_traverse, compobject_traverse},
20572098
{Py_tp_methods, Decomp_methods},
20582099
{Py_tp_members, Decomp_members},
2100+
{Py_tp_getset, Decomp_getset},
20592101
{0, 0},
20602102
};
20612103

@@ -2075,6 +2117,7 @@ static PyType_Slot ZlibDecompressor_type_slots[] = {
20752117
{Py_tp_dealloc, ZlibDecompressor_dealloc},
20762118
{Py_tp_traverse, ZlibDecompressor_traverse},
20772119
{Py_tp_members, ZlibDecompressor_members},
2120+
{Py_tp_getset, ZlibDecompressor_getset},
20782121
{Py_tp_new, zlib__ZlibDecompressor},
20792122
{Py_tp_doc, (char *)zlib__ZlibDecompressor__doc__},
20802123
{Py_tp_methods, ZlibDecompressor_methods},

0 commit comments

Comments
 (0)