@@ -363,59 +363,61 @@ PyUnicode_GetMax(void)
363363int
364364_PyUnicode_CheckConsistency (PyObject * op , int check_content )
365365{
366+ #define ASSERT (expr ) _PyObject_ASSERT(op, (expr))
367+
366368 PyASCIIObject * ascii ;
367369 unsigned int kind ;
368370
369- assert (PyUnicode_Check (op ));
371+ ASSERT (PyUnicode_Check (op ));
370372
371373 ascii = (PyASCIIObject * )op ;
372374 kind = ascii -> state .kind ;
373375
374376 if (ascii -> state .ascii == 1 && ascii -> state .compact == 1 ) {
375- assert (kind == PyUnicode_1BYTE_KIND );
376- assert (ascii -> state .ready == 1 );
377+ ASSERT (kind == PyUnicode_1BYTE_KIND );
378+ ASSERT (ascii -> state .ready == 1 );
377379 }
378380 else {
379381 PyCompactUnicodeObject * compact = (PyCompactUnicodeObject * )op ;
380382 void * data ;
381383
382384 if (ascii -> state .compact == 1 ) {
383385 data = compact + 1 ;
384- assert (kind == PyUnicode_1BYTE_KIND
386+ ASSERT (kind == PyUnicode_1BYTE_KIND
385387 || kind == PyUnicode_2BYTE_KIND
386388 || kind == PyUnicode_4BYTE_KIND );
387- assert (ascii -> state .ascii == 0 );
388- assert (ascii -> state .ready == 1 );
389- assert (compact -> utf8 != data );
389+ ASSERT (ascii -> state .ascii == 0 );
390+ ASSERT (ascii -> state .ready == 1 );
391+ ASSERT (compact -> utf8 != data );
390392 }
391393 else {
392394 PyUnicodeObject * unicode = (PyUnicodeObject * )op ;
393395
394396 data = unicode -> data .any ;
395397 if (kind == PyUnicode_WCHAR_KIND ) {
396- assert (ascii -> length == 0 );
397- assert (ascii -> hash == -1 );
398- assert (ascii -> state .compact == 0 );
399- assert (ascii -> state .ascii == 0 );
400- assert (ascii -> state .ready == 0 );
401- assert (ascii -> state .interned == SSTATE_NOT_INTERNED );
402- assert (ascii -> wstr != NULL );
403- assert (data == NULL );
404- assert (compact -> utf8 == NULL );
398+ ASSERT (ascii -> length == 0 );
399+ ASSERT (ascii -> hash == -1 );
400+ ASSERT (ascii -> state .compact == 0 );
401+ ASSERT (ascii -> state .ascii == 0 );
402+ ASSERT (ascii -> state .ready == 0 );
403+ ASSERT (ascii -> state .interned == SSTATE_NOT_INTERNED );
404+ ASSERT (ascii -> wstr != NULL );
405+ ASSERT (data == NULL );
406+ ASSERT (compact -> utf8 == NULL );
405407 }
406408 else {
407- assert (kind == PyUnicode_1BYTE_KIND
409+ ASSERT (kind == PyUnicode_1BYTE_KIND
408410 || kind == PyUnicode_2BYTE_KIND
409411 || kind == PyUnicode_4BYTE_KIND );
410- assert (ascii -> state .compact == 0 );
411- assert (ascii -> state .ready == 1 );
412- assert (data != NULL );
412+ ASSERT (ascii -> state .compact == 0 );
413+ ASSERT (ascii -> state .ready == 1 );
414+ ASSERT (data != NULL );
413415 if (ascii -> state .ascii ) {
414- assert (compact -> utf8 == data );
415- assert (compact -> utf8_length == ascii -> length );
416+ ASSERT (compact -> utf8 == data );
417+ ASSERT (compact -> utf8_length == ascii -> length );
416418 }
417419 else
418- assert (compact -> utf8 != data );
420+ ASSERT (compact -> utf8 != data );
419421 }
420422 }
421423 if (kind != PyUnicode_WCHAR_KIND ) {
@@ -427,16 +429,16 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content)
427429#endif
428430 )
429431 {
430- assert (ascii -> wstr == data );
431- assert (compact -> wstr_length == ascii -> length );
432+ ASSERT (ascii -> wstr == data );
433+ ASSERT (compact -> wstr_length == ascii -> length );
432434 } else
433- assert (ascii -> wstr != data );
435+ ASSERT (ascii -> wstr != data );
434436 }
435437
436438 if (compact -> utf8 == NULL )
437- assert (compact -> utf8_length == 0 );
439+ ASSERT (compact -> utf8_length == 0 );
438440 if (ascii -> wstr == NULL )
439- assert (compact -> wstr_length == 0 );
441+ ASSERT (compact -> wstr_length == 0 );
440442 }
441443 /* check that the best kind is used */
442444 if (check_content && kind != PyUnicode_WCHAR_KIND )
@@ -455,23 +457,25 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content)
455457 }
456458 if (kind == PyUnicode_1BYTE_KIND ) {
457459 if (ascii -> state .ascii == 0 ) {
458- assert (maxchar >= 128 );
459- assert (maxchar <= 255 );
460+ ASSERT (maxchar >= 128 );
461+ ASSERT (maxchar <= 255 );
460462 }
461463 else
462- assert (maxchar < 128 );
464+ ASSERT (maxchar < 128 );
463465 }
464466 else if (kind == PyUnicode_2BYTE_KIND ) {
465- assert (maxchar >= 0x100 );
466- assert (maxchar <= 0xFFFF );
467+ ASSERT (maxchar >= 0x100 );
468+ ASSERT (maxchar <= 0xFFFF );
467469 }
468470 else {
469- assert (maxchar >= 0x10000 );
470- assert (maxchar <= MAX_UNICODE );
471+ ASSERT (maxchar >= 0x10000 );
472+ ASSERT (maxchar <= MAX_UNICODE );
471473 }
472- assert (PyUnicode_READ (kind , data , ascii -> length ) == 0 );
474+ ASSERT (PyUnicode_READ (kind , data , ascii -> length ) == 0 );
473475 }
474476 return 1 ;
477+
478+ #undef ASSERT
475479}
476480#endif
477481
0 commit comments