@@ -589,7 +589,6 @@ struct compiling {
589
589
PyArena * c_arena ; /* Arena for allocating memory. */
590
590
PyObject * c_filename ; /* filename */
591
591
PyObject * c_normalize ; /* Normalization function from unicodedata. */
592
- PyObject * c_normalize_args ; /* Normalization argument tuple. */
593
592
};
594
593
595
594
static asdl_seq * seq_for_testlist (struct compiling * , const node * );
@@ -624,12 +623,6 @@ init_normalization(struct compiling *c)
624
623
Py_DECREF (m );
625
624
if (!c -> c_normalize )
626
625
return 0 ;
627
- c -> c_normalize_args = Py_BuildValue ("(sN)" , "NFKC" , Py_None );
628
- if (!c -> c_normalize_args ) {
629
- Py_CLEAR (c -> c_normalize );
630
- return 0 ;
631
- }
632
- PyTuple_SET_ITEM (c -> c_normalize_args , 1 , NULL );
633
626
return 1 ;
634
627
}
635
628
@@ -645,15 +638,29 @@ new_identifier(const char *n, struct compiling *c)
645
638
identifier; if so, normalize to NFKC. */
646
639
if (!PyUnicode_IS_ASCII (id )) {
647
640
PyObject * id2 ;
641
+ _Py_IDENTIFIER (NFKC );
648
642
if (!c -> c_normalize && !init_normalization (c )) {
649
643
Py_DECREF (id );
650
644
return NULL ;
651
645
}
652
- PyTuple_SET_ITEM (c -> c_normalize_args , 1 , id );
653
- id2 = PyObject_Call (c -> c_normalize , c -> c_normalize_args , NULL );
646
+ PyObject * form = _PyUnicode_FromId (& PyId_NFKC );
647
+ if (form == NULL ) {
648
+ Py_DECREF (id );
649
+ return NULL ;
650
+ }
651
+ PyObject * args [2 ] = {form , id };
652
+ id2 = _PyObject_FastCall (c -> c_normalize , args , 2 );
654
653
Py_DECREF (id );
655
654
if (!id2 )
656
655
return NULL ;
656
+ if (!PyUnicode_Check (id2 )) {
657
+ PyErr_Format (PyExc_TypeError ,
658
+ "unicodedata.normalize() must return a string, not "
659
+ "%.200s" ,
660
+ Py_TYPE (id2 )-> tp_name );
661
+ Py_DECREF (id2 );
662
+ return NULL ;
663
+ }
657
664
id = id2 ;
658
665
}
659
666
PyUnicode_InternInPlace (& id );
@@ -773,7 +780,6 @@ PyAST_FromNodeObject(const node *n, PyCompilerFlags *flags,
773
780
/* borrowed reference */
774
781
c .c_filename = filename ;
775
782
c .c_normalize = NULL ;
776
- c .c_normalize_args = NULL ;
777
783
778
784
if (TYPE (n ) == encoding_decl )
779
785
n = CHILD (n , 0 );
@@ -866,8 +872,6 @@ PyAST_FromNodeObject(const node *n, PyCompilerFlags *flags,
866
872
out :
867
873
if (c .c_normalize ) {
868
874
Py_DECREF (c .c_normalize );
869
- PyTuple_SET_ITEM (c .c_normalize_args , 1 , NULL );
870
- Py_DECREF (c .c_normalize_args );
871
875
}
872
876
return res ;
873
877
}
0 commit comments