gh-95534: Convert `ZlibDecompressor.__new__` to AC (#137923)

This commit is contained in:
Adam Turner 2025-08-19 09:52:13 +01:00 committed by GitHub
parent 06dd63501a
commit bb75dec87f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 118 additions and 46 deletions

View file

@ -1369,9 +1369,9 @@ typedef struct {
} ZlibDecompressor;
/*[clinic input]
class zlib.ZlibDecompressor "ZlibDecompressor *" "&ZlibDecompressorType"
class zlib._ZlibDecompressor "ZlibDecompressor *" "&ZlibDecompressorType"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=0658178ab94645df]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=49151d1d703e6bcc]*/
static void
ZlibDecompressor_dealloc(PyObject *op)
@ -1670,7 +1670,7 @@ decompress(ZlibDecompressor *self, uint8_t *data,
/*[clinic input]
@permit_long_docstring_body
zlib.ZlibDecompressor.decompress
zlib._ZlibDecompressor.decompress
data: Py_buffer
max_length: Py_ssize_t=-1
@ -1692,9 +1692,10 @@ the unused_data attribute.
[clinic start generated code]*/
static PyObject *
zlib_ZlibDecompressor_decompress_impl(ZlibDecompressor *self,
Py_buffer *data, Py_ssize_t max_length)
/*[clinic end generated code: output=990d32787b775f85 input=fcf9f974de5d02b1]*/
zlib__ZlibDecompressor_decompress_impl(ZlibDecompressor *self,
Py_buffer *data,
Py_ssize_t max_length)
/*[clinic end generated code: output=ac00dcf73e843e99 input=c9278e791be1152b]*/
{
PyObject *result = NULL;
@ -1710,38 +1711,28 @@ zlib_ZlibDecompressor_decompress_impl(ZlibDecompressor *self,
return result;
}
PyDoc_STRVAR(ZlibDecompressor__new____doc__,
"_ZlibDecompressor(wbits=15, zdict=b\'\')\n"
"--\n"
"\n"
"Create a decompressor object for decompressing data incrementally.\n"
"\n"
" wbits = 15\n"
" zdict\n"
" The predefined compression dictionary. This is a sequence of bytes\n"
" (such as a bytes object) containing subsequences that are expected\n"
" to occur frequently in the data that is to be compressed. Those\n"
" subsequences that are expected to be most common should come at the\n"
" end of the dictionary. This must be the same dictionary as used by the\n"
" compressor that produced the input data.\n"
"\n");
/*[clinic input]
@classmethod
zlib._ZlibDecompressor.__new__
wbits: int(c_default='MAX_WBITS') = MAX_WBITS
zdict: object(c_default='NULL') = b''
The predefined compression dictionary. This is a sequence of bytes
(such as a bytes object) containing subsequences that are expected
to occur frequently in the data that is to be compressed. Those
subsequences that are expected to be most common should come at the
end of the dictionary. This must be the same dictionary as used by the
compressor that produced the input data.
Create a decompressor object for decompressing data incrementally.
[clinic start generated code]*/
static PyObject *
ZlibDecompressor__new__(PyTypeObject *cls,
PyObject *args,
PyObject *kwargs)
zlib__ZlibDecompressor_impl(PyTypeObject *type, int wbits, PyObject *zdict)
/*[clinic end generated code: output=1065607df0d33baa input=9ebad0be6de226e2]*/
{
static char *keywords[] = {"wbits", "zdict", NULL};
static const char * const format = "|iO:_ZlibDecompressor";
int wbits = MAX_WBITS;
PyObject *zdict = NULL;
zlibstate *state = PyType_GetModuleState(cls);
if (!PyArg_ParseTupleAndKeywords(
args, kwargs, format, keywords, &wbits, &zdict)) {
return NULL;
}
ZlibDecompressor *self = PyObject_New(ZlibDecompressor, cls);
zlibstate *state = PyType_GetModuleState(type);
ZlibDecompressor *self = PyObject_New(ZlibDecompressor, type);
if (self == NULL) {
return NULL;
}
@ -1817,7 +1808,7 @@ static PyMethodDef Decomp_methods[] =
};
static PyMethodDef ZlibDecompressor_methods[] = {
ZLIB_ZLIBDECOMPRESSOR_DECOMPRESS_METHODDEF
ZLIB__ZLIBDECOMPRESSOR_DECOMPRESS_METHODDEF
{NULL}
};
@ -2052,8 +2043,8 @@ static PyType_Spec Decomptype_spec = {
static PyType_Slot ZlibDecompressor_type_slots[] = {
{Py_tp_dealloc, ZlibDecompressor_dealloc},
{Py_tp_members, ZlibDecompressor_members},
{Py_tp_new, ZlibDecompressor__new__},
{Py_tp_doc, (char *)ZlibDecompressor__new____doc__},
{Py_tp_new, zlib__ZlibDecompressor},
{Py_tp_doc, (char *)zlib__ZlibDecompressor__doc__},
{Py_tp_methods, ZlibDecompressor_methods},
{0, 0},
};