@@ -1351,36 +1351,6 @@ zlib_Decompress_flush_impl(compobject *self, PyTypeObject *cls,
1351
1351
return RetVal ;
1352
1352
}
1353
1353
1354
- #include "clinic/zlibmodule.c.h"
1355
-
1356
- static PyMethodDef comp_methods [] =
1357
<
8000
/td>
- {
1358
- ZLIB_COMPRESS_COMPRESS_METHODDEF
1359
- ZLIB_COMPRESS_FLUSH_METHODDEF
1360
- ZLIB_COMPRESS_COPY_METHODDEF
1361
- ZLIB_COMPRESS___COPY___METHODDEF
1362
- ZLIB_COMPRESS___DEEPCOPY___METHODDEF
1363
- {NULL , NULL }
1364
- };
1365
-
1366
- static PyMethodDef Decomp_methods [] =
1367
- {
1368
- ZLIB_DECOMPRESS_DECOMPRESS_METHODDEF
1369
- ZLIB_DECOMPRESS_FLUSH_METHODDEF
1370
- ZLIB_DECOMPRESS_COPY_METHODDEF
1371
- ZLIB_DECOMPRESS___COPY___METHODDEF
1372
- ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF
1373
- {NULL , NULL }
1374
- };
1375
-
1376
- #define COMP_OFF (x ) offsetof(compobject, x)
1377
- static PyMemberDef Decomp_members [] = {
1378
- {"unused_data" , T_OBJECT , COMP_OFF (unused_data ), READONLY },
1379
- {"unconsumed_tail" , T_OBJECT , COMP_OFF (unconsumed_tail ), READONLY },
1380
- {"eof" , T_BOOL , COMP_OFF (eof ), READONLY },
1381
- {NULL },
1382
- };
1383
-
1384
1354
1385
1355
typedef struct {
1386
1356
PyObject_HEAD
@@ -1484,6 +1454,7 @@ decompress_buf(ZlibDecompressor *self, Py_ssize_t max_length)
1484
1454
PyObject * RetVal = NULL ;
1485
1455
Py_ssize_t hard_limit ;
1486
1456
Py_ssize_t obuflen ;
1457
+ zlibstate * state = PyType_GetModuleState (Py_TYPE (self ));
1487
1458
1488
1459
int err ;
1489
1460
@@ -1680,77 +1651,116 @@ decompress(ZlibDecompressor *self, PyTypeObject *cls, uint8_t *data,
1680
1651
return NULL ;
1681
1652
}
1682
1653
1683
- PyDoc_STRVAR (igzip_lib_IgzipDecompressor___init____doc__ ,
1684
- "IgzipDecompressor(flag=0, hist_bits =15, zdict=b\'\')\n"
1654
+ PyDoc_STRVAR (ZlibDecompressor__new____doc__ ,
1655
+ "_ZlibDecompressor(wbits =15, zdict=b\'\')\n"
1685
1656
"--\n"
1686
1657
"\n"
1687
1658
"Create a decompressor object for decompressing data incrementally.\n"
1688
1659
"\n"
1689
- " wbits\n"
1690
- " The lookback distance is 2 ^ hist_bits.\n"
1660
+ " wbits = 15\n"
1691
1661
" zdict\n"
1692
- " Dictionary used for decompressing the data \n"
1693
- "\n"
1694
- "For one-shot decompression, use the decompress() function instead. " );
1662
+ " The predefined compression dictionary. This must be the same \n"
1663
+ " dictionary as used by the compressor that produced the input data. \n"
1664
+ "\n " );
1695
1665
1696
1666
static PyObject *
1697
- igzip_lib_IgzipDecompressor__new__ (PyTypeObject * type ,
1698
- PyObject * args ,
1699
- PyObject * kwargs )
1667
+ ZlibDecompressor__new__ (PyTypeObject * cls ,
1668
+ PyObject * args ,
1669
+ PyObject * kwargs )
1700
1670
{
1701
- static char * keywords [] = {"flag" , "hist_bits" , "zdict" , NULL };
1702
- static char * format = "|iiO:IgzipDecompressor" ;
1703
- int flag = ISAL_DEFLATE ;
1704
- int hist_bits = ISAL_DEF_MAX_HIST_BITS ;
1671
+ static char * keywords [] = {"wbits" , "zdict" , NULL };
1672
+ static char * format = "|iO:IgzipDecompressor" ;
1673
+ int wbits = MAX_WBITS ;
1705
1674
PyObject * zdict = NULL ;
1675
+ zlibstate * state = PyType_GetModuleState (cls );
1706
1676
1707
1677
if (!PyArg_ParseTupleAndKeywords (
1708
- args , kwargs , format , keywords , & flag , & hist_bits , & zdict )) {
1678
+ args , kwargs , format , keywords , & wbits , & zdict )) {
1709
1679
return NULL ;
1710
1680
}
1711
- IgzipDecompressor * self = PyObject_New (IgzipDecompressor , type );
1681
+ ZlibDecompressor * self = PyObject_New (ZlibDecompressor , cls );
1712
1682
int err ;
1713
1683
self -> eof = 0 ;
1714
1684
self -> needs_input = 1 ;
1715
1685
self -> avail_in_real = 0 ;
1716
1686
self -> input_buffer = NULL ;
1717
1687
self -> input_buffer_size = 0 ;
1718
1688
self -> zdict = zdict ;
1689
+ self -> zst .opaque = NULL ;
1690
+ self -> zst .zalloc = PyZlib_Malloc ;
1691
+ self -> zst .zfree = PyZlib_Free ;
1719
1692
self -> unused_data = PyBytes_FromStringAndSize (NULL , 0 );
1720
1693
if (self -> unused_data == NULL ) {
1721
1694
Py_CLEAR (self );
1722
1695
return NULL ;
1723
1696
}
1724
- isal_inflate_init (& (self -> state ));
1725
- self -> state .hist_bits = hist_bits ;
1726
- self -> state .crc_flag = flag ;
1727
- if (self -> zdict != NULL ){
1728
- Py_buffer zdict_buf ;
1729
- if (PyObject_GetBuffer (self -> zdict , & zdict_buf , PyBUF_SIMPLE ) == -1 ) {
1730
- Py_CLEAR (self );
1697
+ int err = inflateInit2 (& (self -> zst ), wbits );
1698
+ switch (err ) {
1699
+ case Z_OK :
1700
+ self -> is_initialised = 1 ;
1701
+ if (self -> zdict != NULL && wbits < 0 ) {
1702
+ #ifdef AT_LEAST_ZLIB_1_2_2_1
1703
+ if (set_inflate_zdict (state , self ) < 0 ) {
1704
+ Py_DECREF (self );
1731
1705
return NULL ;
1732
- }
1733
- if (( size_t ) zdict_buf . len > UINT32_MAX ) {
1734
- PyErr_SetString ( PyExc_OverflowError ,
1735
- "zdict length does not fit in an unsigned 32-bits int" );
1736
- PyBuffer_Release ( & zdict_buf );
1737
- Py_CLEAR (self );
1706
+ }
1707
+ #else
1708
+ PyErr_Format ( state -> ZlibError ,
1709
+ "zlib version %s does not allow raw inflate with dictionary" ,
1710
+ ZLIB_VERSION );
1711
+ Py_DECREF (self );
1738
1712
return NULL ;
1713
+ #endif
1739
1714
}
1740
- err = isal_inflate_set_dict (& (self -> state ), zdict_buf .buf ,
1741
- (uint32_t )zdict_buf .len );
1742
- PyBuffer_Release (& zdict_buf );
1743
- if (err != ISAL_DECOMP_OK ) {
1744
- isal_inflate_error (err );
1745
- Py_CLEAR (self );
1746
- return NULL ;
1747
- }
1715
+ return (PyObject * )self ;
1716
+ case Z_STREAM_ERROR :
1717
+ Py_DECREF (self );
1718
+ PyErr_SetString (PyExc_ValueError , "Invalid initialization option" );
1719
+ return NULL ;
1720
+ case Z_MEM_ERROR :
1721
+ Py_DECREF (self );
1722
+ PyErr_SetString (PyExc_MemoryError ,
1723
+ "Can't allocate memory for decompression object" );
1724
+ return NULL ;
1725
+ default :
1726
+ zlib_error (state , self -> zst , err , "while creating decompression object" );
1727
+ Py_DECREF (self );
1728
+ return NULL ;
1748
1729
}
1749
- return (PyObject * )self ;
1750
1730
}
1751
1731
1732
+ #include "clinic/zlibmodule.c.h"
1733
+
1734
+ static PyMethodDef comp_methods [] =
1735
+ {
1736
+ ZLIB_COMPRESS_COMPRESS_METHODDEF
1737
+ ZLIB_COMPRESS_FLUSH_METHODDEF
1738
+ ZLIB_COMPRESS_COPY_METHODDEF
1739
+ ZLIB_COMPRESS___COPY___METHODDEF
1740
+ ZLIB_COMPRESS___DEEPCOPY___METHODDEF
1741
+ {NULL , NULL }
1742
+ };
1743
+
1744
+ static PyMethodDef Decomp_methods [] =
1745
+ {
1746
+ ZLIB_DECOMPRESS_DECOMPRESS_METHODDEF
1747
+ ZLIB_DECOMPRESS_FLUSH_METHODDEF
1748
+ ZLIB_DECOMPRESS_COPY_METHODDEF
1749
+ ZLIB_DECOMPRESS___COPY___METHODDEF
1750
+ ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF
1751
+ {NULL , NULL }
1752
+ };
1753
+
1754
+ #define COMP_OFF (x ) offsetof(compobject, x)
1755
+ static PyMemberDef Decomp_members [] = {
1756
+ {"unused_data" , T_OBJECT , COMP_OFF (unused_data ), READONLY },
1757
+ {"unconsumed_tail" , T_OBJECT , COMP_OFF (unconsumed_tail ), READONLY },
1758
+ {"eof" , T_BOOL , COMP_OFF (eof ), READONLY },
1759
+ {NULL },
1760
+ };
1761
+
1752
1762
static PyMethodDef IgzipDecompressor_methods [] = {
1753
- IGZIP_LIB_IGZIPDECOMPRESSOR_DECOMPRESS_METHODDEF ,
1763
+ ZLIBCOMPRESSOR_DECOMPRESS_METHODDEF ,
1754
1764
{NULL }
1755
1765
};
1756
1766
0 commit comments