@@ -44,50 +44,6 @@ IgzipDecompressor_dealloc(IgzipDecompressor *self)
44
44
Py_TYPE (self )-> tp_free ((PyObject * )self );
45
45
}
46
46
47
- static int
48
- igzip_lib_IgzipDecompressor___init___impl (IgzipDecompressor * self ,
49
- int flag ,
50
- int hist_bits ,
51
- PyObject * zdict )
52
- {
53
- int err ;
54
- self -> needs_input = 1 ;
55
- self -> avail_in_real = 0 ;
56
- self -> input_buffer = NULL ;
57
- self -> input_buffer_size = 0 ;
58
- self -> zdict = zdict ;
59
- Py_XSETREF (self -> unused_data , PyBytes_FromStringAndSize (NULL , 0 ));
60
- if (self -> unused_data == NULL )
61
- goto error ;
62
- isal_inflate_init (& (self -> state ));
63
- self -> state .hist_bits = hist_bits ;
64
- self -> state .crc_flag = flag ;
65
- if (self -> zdict != NULL ){
66
- Py_buffer zdict_buf ;
67
- if (PyObject_GetBuffer (self -> zdict , & zdict_buf , PyBUF_SIMPLE ) == -1 ) {
68
- goto error ;
69
- }
70
- if ((size_t )zdict_buf .len > UINT32_MAX ) {
71
- PyErr_SetString (PyExc_OverflowError ,
72
- "zdict length does not fit in an unsigned 32-bits int" );
73
- PyBuffer_Release (& zdict_buf );
74
- }
75
- err = isal_inflate_set_dict (& (self -> state ), zdict_buf .buf ,
76
- (uint32_t )zdict_buf .len );
77
- PyBuffer_Release (& zdict_buf );
78
- if (err != ISAL_DECOMP_OK ) {
79
- isal_inflate_error (err );
80
- goto error ;
81
- }
82
- }
83
- return 0 ;
84
-
85
- error :
86
- Py_CLEAR (self -> unused_data );
87
- Py_CLEAR (self -> zdict );
88
- return -1 ;
89
- }
90
-
91
47
/* Decompress data of length d->bzs_avail_in_real in d->state.next_in. The output
92
48
buffer is allocated dynamically and returned. At most max_length bytes are
93
49
returned, so some of the input may not be consumed. d->state.next_in and
@@ -430,8 +386,10 @@ PyDoc_STRVAR(igzip_lib_IgzipDecompressor___init____doc__,
430
386
"\n"
431
387
"For one-shot decompression, use the decompress() function instead." );
432
388
433
- static int
434
- igzip_lib_IgzipDecompressor___init__ (PyObject * self , PyObject * args , PyObject * kwargs )
389
+ static PyObject *
390
+ igzip_lib_IgzipDecompressor__new__ (PyTypeObject * type ,
391
+ PyObject * args ,
392
+ PyObject * kwargs )
435
393
{
436
394
char * keywords [] = {"flag" , "hist_bits" , "zdict" , NULL };
437
395
char * format = "|iiO:IgzipDecompressor" ;
@@ -441,9 +399,47 @@ igzip_lib_IgzipDecompressor___init__(PyObject *self, PyObject *args, PyObject *k
441
399
442
400
if (!PyArg_ParseTupleAndKeywords (
443
401
args , kwargs , format , keywords , & flag , & hist_bits , & zdict )) {
444
- return -1 ;
402
+ return NULL ;
403
+ }
404
+ IgzipDecompressor * self = PyObject_New (IgzipDecompressor , type );
405
+ int err ;
406
+ self -> eof = 0 ;
407
+ self -> needs_input = 1 ;
408
+ self -> avail_in_real = 0 ;
409
+ self -> input_buffer = NULL ;
410
+ self -> input_buffer_size = 0 ;
411
+ self -> zdict = zdict ;
412
+ self -> unused_data = PyBytes_FromStringAndSize (NULL , 0 );
413
+ if (self -> unused_data == NULL ) {
414
+ Py_CLEAR (self );
415
+ return NULL ;
416
+ }
417
+ isal_inflate_init (& (self -> state ));
418
+ self -> state .hist_bits = hist_bits ;
419
+ self -> state .crc_flag = flag ;
420
+ if (self -> zdict != NULL ){
421
+ Py_buffer zdict_buf ;
422
+ if (PyObject_GetBuffer (self -> zdict , & zdict_buf , PyBUF_SIMPLE ) == -1 ) {
423
+ Py_CLEAR (self );
424
+ return -1 ;;
425
+ }
426
+ if ((size_t )zdict_buf .len > UINT32_MAX ) {
427
+ PyErr_SetString (PyExc_OverflowError ,
428
+ "zdict length does not fit in an unsigned 32-bits int" );
429
+ PyBuffer_Release (& zdict_buf );
430
+ Py_CLEAR (self );
431
+ return NULL ;
432
+ }
433
+ err = isal_inflate_set_dict (& (self -> state ), zdict_buf .buf ,
434
+ (uint32_t )zdict_buf .len );
435
+ PyBuffer_Release (& zdict_buf );
436
+ if (err != ISAL_DECOMP_OK ) {
437
+ isal_inflate_error (err );
438
+ Py_CLEAR (self );
439
+ return NULL ;
440
+ }
445
441
}
446
- return igzip_lib_IgzipDecompressor___init___impl (( IgzipDecompressor * )self , flag , hist_bits , zdict ) ;
442
+ return ( PyObject * )self ;
447
443
}
448
444
449
445
static PyMethodDef IgzipDecompressor_methods [] = {
@@ -484,8 +480,7 @@ static PyTypeObject IgzipDecompressor_Type = {
484
480
.tp_doc = igzip_lib_IgzipDecompressor___init____doc__ ,
485
481
.tp_methods = IgzipDecompressor_methods ,
486
482
.tp_members = IgzipDecompressor_members ,
487
- .tp_init = igzip_lib_IgzipDecompressor___init__ ,
488
- .tp_new = PyType_GenericNew ,
483
+ .tp_new = igzip_lib_IgzipDecompressor__new__ ,
489
484
};
490
485
491
486
static PyMethodDef IgzipLibMethods [] = {
0 commit comments