@@ -291,7 +291,8 @@ BZ2_Free(void* ctx, void *ptr)
291
291
}
292
292
293
293
/*[clinic input]
294
- _bz2.BZ2Compressor.__init__
294
+ @classmethod
295
+ _bz2.BZ2Compressor.__new__
295
296
296
297
compresslevel: int = 9
297
298
Compression level, as a number between 1 and 9.
@@ -302,22 +303,30 @@ Create a compressor object for compressing data incrementally.
302
303
For one-shot compression, use the compress() function instead.
303
304
[clinic start generated code]*/
304
305
305
- static int
306
- _bz2_BZ2Compressor___init___impl ( BZ2Compressor * self , int compresslevel )
307
- /*[clinic end generated code: output=c4e6adfd02963827 input=4e1ff7b8394b6e9a ]*/
306
+ static PyObject *
307
+ _bz2_BZ2Compressor_impl ( PyTypeObject * type , int compresslevel )
308
+ /*[clinic end generated code: output=83346c96beaacad7 input=d4500d2a52c8b263 ]*/
308
309
{
309
310
int bzerror ;
311
+ BZ2Compressor * self ;
310
312
311
313
if (!(1 <= compresslevel && compresslevel <= 9 )) {
312
314
PyErr_SetString (PyExc_ValueError ,
313
315
"compresslevel must be between 1 and 9" );
314
- return -1 ;
316
+ return NULL ;
317
+ }
318
+
319
+ assert (type != NULL && type -> tp_alloc != NULL );
320
+ self = (BZ2Compressor * )type -> tp_alloc (type , 0 );
321
+ if (self == NULL ) {
322
+ return NULL ;
315
323
}
316
324
317
325
self -> lock = PyThread_allocate_lock ();
318
326
if (self -> lock == NULL ) {
327
+ Py_DECREF (self );
319
328
PyErr_SetString (PyExc_MemoryError , "Unable to allocate lock" );
320
- return -1 ;
329
+ return NULL ;
321
330
}
322
331
323
332
self -> bzs .opaque = NULL ;
@@ -327,12 +336,11 @@ _bz2_BZ2Compressor___init___impl(BZ2Compressor *self, int compresslevel)
327
336
if (catch_bz2_error (bzerror ))
328
337
goto error ;
329
338
330
- return 0 ;
339
+ return ( PyObject * ) self ;
331
340
332
341
error :
333
- PyThread_free_lock (self -> lock );
334
- self -> lock = NULL ;
335
- return -1 ;
342
+ Py_DECREF (self );
343
+ return NULL ;
336
344
}
337
345
338
346
static void
@@ -373,7 +381,7 @@ static PyTypeObject BZ2Compressor_Type = {
373
381
0 , /* tp_setattro */
374
382
0 , /* tp_as_buffer */
375
383
Py_TPFLAGS_DEFAULT , /* tp_flags */
376
- _bz2_BZ2Compressor___init____doc__ , /* tp_doc */
384
+ _bz2_BZ2Compressor__doc__ , /* tp_doc */
377
385
0 , /* tp_traverse */
378
386
0 , /* tp_clear */
379
387
0 , /* tp_richcompare */
@@ -388,9 +396,9 @@ static PyTypeObject BZ2Compressor_Type = {
388
396
0 , /* tp_descr_get */
389
397
0 , /* tp_descr_set */
390
398
0 , /* tp_dictoffset */
391
- _bz2_BZ2Compressor___init__ , /* tp_init */
399
+ 0 , /* tp_init */
392
400
0 , /* tp_alloc */
393
- PyType_GenericNew , /* tp_new */
401
+ _bz2_BZ2Compressor , /* tp_new */
394
402
};
395
403
396
404
@@ -621,44 +629,51 @@ BZ2Decompressor_getstate(BZ2Decompressor *self, PyObject *noargs)
621
629
}
622
630
623
631
/*[clinic input]
624
- _bz2.BZ2Decompressor.__init__
632
+ @classmethod
633
+ _bz2.BZ2Decompressor.__new__
625
634
626
635
Create a decompressor object for decompressing data incrementally.
627
636
628
637
For one-shot decompression, use the decompress() function instead.
629
638
[clinic start generated code]*/
630
639
631
- static int
632
- _bz2_BZ2Decompressor___init___impl ( BZ2Decompressor * self )
633
- /*[clinic end generated code: output=e4d2b9bb866ab8f1 input=95f6500dcda60088 ]*/
640
+ static PyObject *
641
+ _bz2_BZ2Decompressor_impl ( PyTypeObject * type )
642
+ /*[clinic end generated code: output=5150d51ccaab220e input=b87413ce51853528 ]*/
634
643
{
644
+ BZ2Decompressor * self ;
635
645
int bzerror ;
636
646
647
+ assert (type != NULL && type -> tp_alloc != NULL );
648
+ self = (BZ2Decompressor * )type -> tp_alloc (type , 0 );
649
+ if (self == NULL ) {
650
+ return NULL ;
651
+ }
652
+
637
653
self -> lock = PyThread_allocate_lock ();
638
654
if (self -> lock == NULL ) {
655
+ Py_DECREF (self );
639
656
PyErr_SetString (PyExc_MemoryError , "Unable to allocate lock" );
640
- return -1 ;
657
+ return NULL ;
641
658
}
642
659
643
660
self -> needs_input = 1 ;
644
661
self -> bzs_avail_in_real = 0 ;
645
662
self -> input_buffer = NULL ;
646
663
self -> input_buffer_size = 0 ;
647
- Py_XSETREF ( self -> unused_data , PyBytes_FromStringAndSize (NULL , 0 ) );
664
+ self -> unused_data = PyBytes_FromStringAndSize (NULL , 0 );
648
665
if (self -> unused_data == NULL )
649
666
goto error ;
650
667
651
668
bzerror = BZ2_bzDecompressInit (& self -> bzs , 0 , 0 );
652
669
if (catch_bz2_error (bzerror ))
653
670
goto error ;
654
671
655
- return 0 ;
672
+ return ( PyObject * ) self ;
656
673
657
674
error :
658
- Py_CLEAR (self -> unused_data );
659
- PyThread_free_lock (self -> lock );
660
- self -> lock = NULL ;
661
- return -1 ;
675
+ Py_DECREF (self );
676
+ return NULL ;
662
677
}
663
678
664
679
static void
@@ -719,7 +734,7 @@ static PyTypeObject BZ2Decompressor_Type = {
719
734
0 , /* tp_setattro */
720
735
0 , /* tp_as_buffer */
721
736
Py_TPFLAGS_DEFAULT , /* tp_flags */
722
- _bz2_BZ2Decompressor___init____doc__ , /* tp_doc */
737
+ _bz2_BZ2Decompressor__doc__ , /* tp_doc */
723
738
0 , /* tp_traverse */
724
739
0 , /* tp_clear */
725
740
0 , /* tp_richcompare */
@@ -734,9 +749,9 @@ static PyTypeObject BZ2Decompressor_Type = {
734
749
0 , /* tp_descr_get */
735
750
0 , /* tp_descr_set */
736
751
0 , /* tp_dictoffset */
737
- _bz2_BZ2Decompressor___init__ , /* tp_init */
752
+ 0 , /* tp_init */
738
753
0 , /* tp_alloc */
739
- PyType_GenericNew , /* tp_new */
754
+ _bz2_BZ2Decompressor , /* tp_new */
740
755
};
741
756
742
757
0 commit comments