@@ -594,7 +594,6 @@ struct compiling {
594
594
PyArena * c_arena ; /* Arena for allocating memory. */
595
595
PyObject * c_filename ; /* filename */
596
596
PyObject * c_normalize ; /* Normalization function from unicodedata. */
597
- PyObject * c_normalize_args ; /* Normalization argument tuple. */
598
597
};
599
598
600
599
static asdl_seq * seq_for_testlist (struct compiling * , const node * );
@@ -631,12 +630,6 @@ init_normalization(struct compiling *c)
631
630
Py_DECREF (m );
632
631
if (!c -> c_normalize )
633
632
return 0 ;
634
- c -> c_normalize_args = Py_BuildValue ("(sN)" , "NFKC" , Py_None );
635
- if (!c -> c_normalize_args ) {
636
- Py_CLEAR (c -> c_normalize );
637
- return 0 ;
638
- }
639
- PyTuple_SET_ITEM (c -> c_normalize_args , 1 , NULL );
640
633
return 1 ;
641
634
}
642
635
@@ -652,15 +645,29 @@ new_identifier(const char *n, struct compiling *c)
652
645
identifier; if so, normalize to NFKC. */
653
646
if (!PyUnicode_IS_ASCII (id )) {
654
647
PyObject * id2 ;
648
+ _Py_IDENTIFIER (NFKC );
655
649
if (!c -> c_normalize && !init_normalization (c )) {
656
650
Py_DECREF (id );
657
651
return NULL ;
658
652
}
659
- PyTuple_SET_ITEM (c -> c_normalize_args , 1 , id );
660
- id2 = PyObject_Call (c -> c_normalize , c -> c_normalize_args , NULL );
653
+ PyObject * form = _PyUnicode_FromId (& PyId_NFKC );
654
+ if (form == NULL ) {
655
+ Py_DECREF (id );
656
+ return NULL ;
657
+ }
658
+ PyObject * args [2 ] = {form , id };
659
+ id2 = _PyObject_FastCall (c -> c_normalize , args , 2 );
661
660
Py_DECREF (id );
662
661
if (!id2 )
663
662
return NULL ;
663
+ if (!PyUnicode_Check (id2 )) {
664
+ PyErr_Format (PyExc_TypeError ,
665
+ "unicodedata.normalize() must return a string, not "
666
+ "%.200s" ,
667
+ Py_TYPE (id2 )-> tp_name );
668
+ Py_DECREF (id2 );
669
+ return NULL ;
670
+ }
664
671
id = id2 ;
665
672
}
666
673
PyUnicode_InternInPlace (& id );
@@ -779,7 +786,6 @@ PyAST_FromNodeObject(const node *n, PyCompilerFlags *flags,
779
786
/* borrowed reference */
780
787
c .c_filename = filename ;
781
788
c .c_normalize = NULL ;
782
- c .c_normalize_args = NULL ;
783
789
784
790
if (TYPE (n ) == encoding_decl )
785
791
n = CHILD (n , 0 );
@@ -872,8 +878,6 @@ PyAST_FromNodeObject(const node *n, PyCompilerFlags *flags,
872
878
out :
873
879
if (c .c_normalize ) {
874
880
Py_DECREF (c .c_normalize );
875
- PyTuple_SET_ITEM (c .c_normalize_args , 1 , NULL );
876
- Py_DECREF (c .c_normalize_args );
877
881
}
878
882
return res ;
879
883
}
0 commit comments