@@ -403,32 +403,35 @@ PyObject_Compare(PyObject *v, PyObject *w)
403403 int c ;
404404 if (!PyInstance_Check (v ))
405405 return - PyObject_Compare (w , v );
406- if (++ _PyCompareState_nesting > NESTING_LIMIT ) {
406+ _PyCompareState_nesting ++ ;
407+ if (_PyCompareState_nesting > NESTING_LIMIT ) {
407408 PyObject * inprogress , * pair ;
408409
409410 inprogress = get_inprogress_dict ();
410411 if (inprogress == NULL ) {
412+ _PyCompareState_nesting -- ;
411413 return -1 ;
412414 }
413415 pair = make_pair (v , w );
414416 if (PyDict_GetItem (inprogress , pair )) {
415417 /* already comparing these objects. assume
416418 they're equal until shown otherwise */
417419 Py_DECREF (pair );
418- -- _PyCompareState_nesting ;
420+ _PyCompareState_nesting -- ;
419421 return 0 ;
420422 }
421423 if (PyDict_SetItem (inprogress , pair , pair ) == -1 ) {
424+ _PyCompareState_nesting -- ;
422425 return -1 ;
423426 }
424427 res = do_cmp (v , w );
425- _PyCompareState_nesting -- ;
426428 /* XXX DelItem shouldn't fail */
427429 PyDict_DelItem (inprogress , pair );
428430 Py_DECREF (pair );
429431 } else {
430432 res = do_cmp (v , w );
431433 }
434+ _PyCompareState_nesting -- ;
432435 if (res == NULL )
433436 return -1 ;
434437 if (!PyInt_Check (res )) {
@@ -486,33 +489,36 @@ PyObject_Compare(PyObject *v, PyObject *w)
486489 if (vtp -> tp_compare == NULL ) {
487490 return (v < w ) ? -1 : 1 ;
488491 }
489- if (++ _PyCompareState_nesting > NESTING_LIMIT
492+ _PyCompareState_nesting ++ ;
493+ if (_PyCompareState_nesting > NESTING_LIMIT
490494 && (vtp -> tp_as_mapping
491495 || (vtp -> tp_as_sequence && !PyString_Check (v )))) {
492496 PyObject * inprogress , * pair ;
493497
494498 inprogress = get_inprogress_dict ();
495499 if (inprogress == NULL ) {
500+ _PyCompareState_nesting -- ;
496501 return -1 ;
497502 }
498503 pair = make_pair (v , w );
499504 if (PyDict_GetItem (inprogress , pair )) {
500505 /* already comparing these objects. assume
501506 they're equal until shown otherwise */
502- _PyCompareState_nesting -- ;
503507 Py_DECREF (pair );
508+ _PyCompareState_nesting -- ;
504509 return 0 ;
505510 }
506511 if (PyDict_SetItem (inprogress , pair , pair ) == -1 ) {
512+ _PyCompareState_nesting -- ;
507513 return -1 ;
508514 }
509515 result = (* vtp -> tp_compare )(v , w );
510- _PyCompareState_nesting -- ;
511516 PyDict_DelItem (inprogress , pair ); /* XXX shouldn't fail */
512517 Py_DECREF (pair );
513518 } else {
514519 result = (* vtp -> tp_compare )(v , w );
515520 }
521+ _PyCompareState_nesting -- ;
516522 return result ;
517523}
518524
0 commit comments