@@ -97,17 +97,16 @@ static int ZstdCompressor_init(ZstdCompressor *self, PyObject *args,
9797 NULL };
9898
9999 int level = 3 ;
100- ZstdCompressionDict * dict = NULL ;
101- ZstdCompressionParametersObject * params = NULL ;
100+ PyObject * dict = NULL ;
101+ PyObject * params = NULL ;
102102 PyObject * writeChecksum = NULL ;
103103 PyObject * writeContentSize = NULL ;
104104 PyObject * writeDictID = NULL ;
105105 int threads = 0 ;
106106
107- if (!PyArg_ParseTupleAndKeywords (args , kwargs , "|iO!O!OOOi:ZstdCompressor" ,
108- kwlist , & level , & ZstdCompressionDictType ,
109- & dict , & ZstdCompressionParametersType ,
110- & params , & writeChecksum , & writeContentSize ,
107+ if (!PyArg_ParseTupleAndKeywords (args , kwargs , "|iOOOOOi:ZstdCompressor" ,
108+ kwlist , & level , & dict , & params ,
109+ & writeChecksum , & writeContentSize ,
111110 & writeDictID , & threads )) {
112111 return -1 ;
113112 }
@@ -122,6 +121,41 @@ static int ZstdCompressor_init(ZstdCompressor *self, PyObject *args,
122121 threads = cpu_count ();
123122 }
124123
124+ if (dict ) {
125+ if (dict == Py_None ) {
126+ dict = NULL ;
127+ }
128+ else if (!PyObject_IsInstance (dict ,
129+ (PyObject * )& ZstdCompressionDictType )) {
130+ PyErr_Format (PyExc_TypeError ,
131+ "dict_data must be zstd.ZstdCompressionDict" );
132+ return -1 ;
133+ }
134+ }
135+
136+ if (params ) {
137+ if (params == Py_None ) {
138+ params = NULL ;
139+ }
140+ else if (!PyObject_IsInstance (
141+ params , (PyObject * )& ZstdCompressionParametersType )) {
142+ PyErr_Format (
143+ PyExc_TypeError ,
144+ "compression_params must be zstd.ZstdCompressionParameters" );
145+ return -1 ;
146+ }
147+ }
148+
149+ if (writeChecksum == Py_None ) {
150+ writeChecksum = NULL ;
151+ }
152+ if (writeContentSize == Py_None ) {
153+ writeContentSize = NULL ;
154+ }
155+ if (writeDictID == Py_None ) {
156+ writeDictID = NULL ;
157+ }
158+
125159 /* We create a ZSTD_CCtx for reuse among multiple operations to reduce the
126160 overhead of each compression operation. */
127161 self -> cctx = ZSTD_createCCtx ();
@@ -166,7 +200,8 @@ static int ZstdCompressor_init(ZstdCompressor *self, PyObject *args,
166200 }
167201
168202 if (params ) {
169- if (set_parameters (self -> params , params )) {
203+ if (set_parameters (self -> params ,
204+ (ZstdCompressionParametersObject * )params )) {
170205 return -1 ;
171206 }
172207 }
@@ -199,7 +234,7 @@ static int ZstdCompressor_init(ZstdCompressor *self, PyObject *args,
199234 }
200235
201236 if (dict ) {
202- self -> dict = dict ;
237+ self -> dict = ( ZstdCompressionDict * ) dict ;
203238 Py_INCREF (dict );
204239 }
205240
0 commit comments