Skip to content

Commit bb75dec

Browse files
authored
gh-95534: Convert ZlibDecompressor.__new__ to AC (#137923)
1 parent 06dd635 commit bb75dec

File tree

2 files changed

+118
-46
lines changed

2 files changed

+118
-46
lines changed

Modules/clinic/zlibmodule.c.h

Lines changed: 89 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/zlibmodule.c

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,9 +1369,9 @@ typedef struct {
13691369
} ZlibDecompressor;
13701370

13711371
/*[clinic input]
1372-
class zlib.ZlibDecompressor "ZlibDecompressor *" "&ZlibDecompressorType"
1372+
class zlib._ZlibDecompressor "ZlibDecompressor *" "&ZlibDecompressorType"
13731373
[clinic start generated code]*/
1374-
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=0658178ab94645df]*/
1374+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=49151d1d703e6bcc]*/
13751375

13761376
static void
13771377
ZlibDecompressor_dealloc(PyObject *op)
@@ -1670,7 +1670,7 @@ decompress(ZlibDecompressor *self, uint8_t *data,
16701670

16711671
/*[clinic input]
16721672
@permit_long_docstring_body
1673-
zlib.ZlibDecompressor.decompress
1673+
zlib._ZlibDecompressor.decompress
16741674
16751675
data: Py_buffer
16761676
max_length: Py_ssize_t=-1
@@ -1692,9 +1692,10 @@ the unused_data attribute.
16921692
[clinic start generated code]*/
16931693

16941694
static PyObject *
1695-
zlib_ZlibDecompressor_decompress_impl(ZlibDecompressor *self,
1696-
Py_buffer *data, Py_ssize_t max_length)
1697-
/*[clinic end generated code: output=990d32787b775f85 input=fcf9f974de5d02b1]*/
1695+
zlib__ZlibDecompressor_decompress_impl(ZlibDecompressor *self,
1696+
Py_buffer *data,
1697+
Py_ssize_t max_length)
1698+
/*[clinic end generated code: output=ac00dcf73e843e99 input=c9278e791be1152b]*/
16981699

16991700
{
17001701
PyObject *result = NULL;
@@ -1710,38 +1711,28 @@ zlib_ZlibDecompressor_decompress_impl(ZlibDecompressor *self,
17101711
return result;
17111712
}
17121713

1713-
PyDoc_STRVAR(ZlibDecompressor__new____doc__,
1714-
"_ZlibDecompressor(wbits=15, zdict=b\'\')\n"
1715-
"--\n"
1716-
"\n"
1717-
"Create a decompressor object for decompressing data incrementally.\n"
1718-
"\n"
1719-
" wbits = 15\n"
1720-
" zdict\n"
1721-
" The predefined compression dictionary. This is a sequence of bytes\n"
1722-
" (such as a bytes object) containing subsequences that are expected\n"
1723-
" to occur frequently in the data that is to be compressed. Those\n"
1724-
" subsequences that are expected to be most common should come at the\n"
1725-
" end of the dictionary. This must be the same dictionary as used by the\n"
1726-
" compressor that produced the input data.\n"
1727-
"\n");
1714+
/*[clinic input]
1715+
@classmethod
1716+
zlib._ZlibDecompressor.__new__
1717+
1718+
wbits: int(c_default='MAX_WBITS') = MAX_WBITS
1719+
zdict: object(c_default='NULL') = b''
1720+
The predefined compression dictionary. This is a sequence of bytes
1721+
(such as a bytes object) containing subsequences that are expected
1722+
to occur frequently in the data that is to be compressed. Those
1723+
subsequences that are expected to be most common should come at the
1724+
end of the dictionary. This must be the same dictionary as used by the
1725+
compressor that produced the input data.
1726+
1727+
Create a decompressor object for decompressing data incrementally.
1728+
[clinic start generated code]*/
17281729

17291730
static PyObject *
1730-
ZlibDecompressor__new__(PyTypeObject *cls,
1731-
PyObject *args,
1732-
PyObject *kwargs)
1731+
zlib__ZlibDecompressor_impl(PyTypeObject *type, int wbits, PyObject *zdict)
1732+
/*[clinic end generated code: output=1065607df0d33baa input=9ebad0be6de226e2]*/
17331733
{
1734-
static char *keywords[] = {"wbits", "zdict", NULL};
1735-
static const char * const format = "|iO:_ZlibDecompressor";
1736-
int wbits = MAX_WBITS;
1737-
PyObject *zdict = NULL;
1738-
zlibstate *state = PyType_GetModuleState(cls);
1739-
1740-
if (!PyArg_ParseTupleAndKeywords(
1741-
args, kwargs, format, keywords, &wbits, &zdict)) {
1742-
return NULL;
1743-
}
1744-
ZlibDecompressor *self = PyObject_New(ZlibDecompressor, cls);
1734+
zlibstate *state = PyType_GetModuleState(type);
1735+
ZlibDecompressor *self = PyObject_New(ZlibDecompressor, type);
17451736
if (self == NULL) {
17461737
return NULL;
17471738
}
@@ -1817,7 +1808,7 @@ static PyMethodDef Decomp_methods[] =
18171808
};
18181809

18191810
static PyMethodDef ZlibDecompressor_methods[] = {
1820-
ZLIB_ZLIBDECOMPRESSOR_DECOMPRESS_METHODDEF
1811+
ZLIB__ZLIBDECOMPRESSOR_DECOMPRESS_METHODDEF
18211812
{NULL}
18221813
};
18231814

@@ -2052,8 +2043,8 @@ static PyType_Spec Decomptype_spec = {
20522043
static PyType_Slot ZlibDecompressor_type_slots[] = {
20532044
{Py_tp_dealloc, ZlibDecompressor_dealloc},
20542045
{Py_tp_members, ZlibDecompressor_members},
2055-
{Py_tp_new, ZlibDecompressor__new__},
2056-
{Py_tp_doc, (char *)ZlibDecompressor__new____doc__},
2046+
{Py_tp_new, zlib__ZlibDecompressor},
2047+
{Py_tp_doc, (char *)zlib__ZlibDecompressor__doc__},
20572048
{Py_tp_methods, ZlibDecompressor_methods},
20582049
{0, 0},
20592050
};

0 commit comments

Comments
 (0)