@@ -333,68 +333,74 @@ getargs_K(PyObject *self, PyObject *args)
333
333
static PyObject *
334
334
test_k_code (PyObject * self , PyObject * Py_UNUSED (ignored ))
335
335
{
336
- PyObject * tuple , * num ;
337
- unsigned long value ;
338
-
339
- tuple = PyTuple_New (1 );
336
+ PyObject * tuple = PyTuple_New (1 );
340
337
if (tuple == NULL ) {
341
338
return NULL ;
342
339
}
343
340
344
341
/* a number larger than ULONG_MAX even on 64-bit platforms */
345
- num = PyLong_FromString ("FFFFFFFFFFFFFFFFFFFFFFFF" , NULL , 16 );
342
+ PyObject * num = PyLong_FromString ("FFFFFFFFFFFFFFFFFFFFFFFF" , NULL , 16 );
346
343
if (num == NULL ) {
347
- return NULL ;
344
+ goto error ;
348
345
}
349
346
350
- value = PyLong_AsUnsignedLongMask (num );
347
+ unsigned long value = PyLong_AsUnsignedLongMask (num );
351
348
if (value != ULONG_MAX ) {
349
+ Py_DECREF (num );
352
350
PyErr_SetString (PyExc_AssertionError ,
353
351
"test_k_code: "
354
352
"PyLong_AsUnsignedLongMask() returned wrong value for long 0xFFF...FFF" );
355
- return NULL ;
353
+ goto error ;
356
354
}
357
355
358
356
PyTuple_SET_ITEM (tuple , 0 , num );
359
357
360
358
value = 0 ;
361
359
if (!PyArg_ParseTuple (tuple , "k:test_k_code" , & value )) {
362
- return NULL ;
360
+ goto error ;
363
361
}
364
362
if (value != ULONG_MAX ) {
365
363
PyErr_SetString (PyExc_AssertionError ,
366
364
"test_k_code: k code returned wrong value for long 0xFFF...FFF" );
367
- return NULL ;
365
+ goto error ;
368
366
}
369
367
370
- Py_DECREF (num );
368
+ Py_DECREF (tuple ); // also clears `num`
369
+ tuple = PyTuple_New (1 );
370
+ if (tuple == NULL ) {
371
+ return NULL ;
372
+ }
371
373
num = PyLong_FromString ("-FFFFFFFF000000000000000042" , NULL , 16 );
372
374
if (num == NULL ) {
373
- return NULL ;
375
+ goto error ;
374
376
}
375
377
376
378
value = PyLong_AsUnsignedLongMask (num );
377
379
if (value != (unsigned long )-0x42 ) {
378
380
PyErr_SetString (PyExc_AssertionError ,
379
381
"test_k_code: "
380
382
"PyLong_AsUnsignedLongMask() returned wrong value for long -0xFFF..000042" );
381
- return NULL ;
383
+ goto error ;
382
384
}
383
385
384
386
PyTuple_SET_ITEM (tuple , 0 , num );
385
387
386
388
value = 0 ;
387
389
if (!PyArg_ParseTuple (tuple , "k:test_k_code" , & value )) {
388
- return NULL ;
390
+ goto error ;
389
391
}
390
392
if (value != (unsigned long )-0x42 ) {
391
393
PyErr_SetString (PyExc_AssertionError ,
392
394
"test_k_code: k code returned wrong value for long -0xFFF..000042" );
393
- return NULL ;
395
+ goto error ;
394
396
}
395
397
396
398
Py_DECREF (tuple );
397
399
Py_RETURN_NONE ;
400
+
401
+ error :
402
+ Py_DECREF (tuple );
403
+ return NULL ;
398
404
}
399
405
400
406
static PyObject *
@@ -684,51 +690,56 @@ getargs_et_hash(PyObject *self, PyObject *args)
684
690
static PyObject *
685
691
test_L_code (PyObject * self , PyObject * Py_UNUSED (ignored ))
686
692
{
687
- PyObject * tuple , * num ;
688
- long long value ;
689
-
690
- tuple = PyTuple_New (1 );
693
+ PyObject * tuple = PyTuple_New (1 );
691
694
if (tuple == NULL ) {
692
695
return NULL ;
693
696
}
694
697
695
- num = PyLong_FromLong (42 );
698
+ PyObject * num = PyLong_FromLong (42 );
696
699
if (num == NULL ) {
697
- return NULL ;
700
+ goto error ;
698
701
}
699
702
700
703
PyTuple_SET_ITEM (tuple , 0 , num );
701
704
702
- value = -1 ;
705
+ long long value = -1 ;
703
706
if (!PyArg_ParseTuple (tuple , "L:test_L_code" , & value )) {
704
- return NULL ;
707
+ goto error ;
705
708
}
706
709
if (value != 42 ) {
707
710
PyErr_SetString (PyExc_AssertionError ,
708
711
"test_L_code: L code returned wrong value for long 42" );
709
- return NULL ;
712
+ goto error ;
710
713
}
711
714
712
- Py_DECREF (num );
715
+ Py_DECREF (tuple ); // also clears `num`
716
+ tuple = PyTuple_New (1 );
717
+ if (tuple == NULL ) {
718
+ return NULL ;
719
+ }
713
720
num = PyLong_FromLong (42 );
714
721
if (num == NULL ) {
715
- return NULL ;
722
+ goto error ;
716
723
}
717
724
718
725
PyTuple_SET_ITEM (tuple , 0 , num );
719
726
720
727
value = -1 ;
721
728
if (!PyArg_ParseTuple (tuple , "L:test_L_code" , & value )) {
722
- return NULL ;
729
+ goto error ;
723
730
}
724
731
if (value != 42 ) {
725
732
PyErr_SetString (PyExc_AssertionError ,
726
733
"test_L_code: L code returned wrong value for int 42" );
727
- return NULL ;
734
+ goto error ;
728
735
}
729
736
730
737
Py_DECREF (tuple );
731
738
Py_RETURN_NONE ;
739
+
740
+ error :
741
+ Py_DECREF (tuple );
742
+ return NULL ;
732
743
}
733
744
734
745
/* Test the s and z codes for PyArg_ParseTuple.
@@ -745,7 +756,7 @@ test_s_code(PyObject *self, PyObject *Py_UNUSED(ignored))
745
756
PyObject * obj = PyUnicode_Decode ("t\xeate" , strlen ("t\xeate" ),
746
757
"latin-1" , NULL );
747
758
if (obj == NULL ) {
748
- return NULL ;
759
+ goto error ;
749
760
}
750
761
751
762
PyTuple_SET_ITEM (tuple , 0 , obj );
@@ -755,15 +766,19 @@ test_s_code(PyObject *self, PyObject *Py_UNUSED(ignored))
755
766
*/
756
767
char * value ;
757
768
if (!PyArg_ParseTuple (tuple , "s:test_s_code1" , & value )) {
758
- return NULL ;
769
+ goto error ;
759
770
}
760
771
761
772
if (!PyArg_ParseTuple (tuple , "z:test_s_code2" , & value )) {
762
- return NULL ;
773
+ goto error ;
763
774
}
764
775
765
776
Py_DECREF (tuple );
766
777
Py_RETURN_NONE ;
778
+
779
+ error :
780
+ Py_DECREF (tuple );
781
+ return NULL ;
767
782
}
768
783
769
784
static PyObject *
0 commit comments