@@ -282,6 +282,7 @@ com_error(c, exc, msg)
282282 object * v ;
283283 char buffer [30 ];
284284 char * s ;
285+ c -> c_errors ++ ;
285286 if (c -> c_lineno <= 1 ) {
286287 /* Unknown line number or single interactive command */
287288 err_setstr (exc , msg );
@@ -296,7 +297,6 @@ com_error(c, exc, msg)
296297 strcat (s , buffer );
297298 err_setval (exc , v );
298299 DECREF (v );
299- c -> c_errors ++ ;
300300}
301301
302302
@@ -913,23 +913,23 @@ com_slice(c, n, op)
913913 }
914914}
915915
916- static int
917- com_argument (c , n , inkeywords )
916+ static void
917+ com_argument (c , n , pkeywords )
918918 struct compiling * c ;
919919 node * n ; /* argument */
920- int inkeywords ;
920+ object * * pkeywords ;
921921{
922922 node * m ;
923923 REQ (n , argument ); /* [test '='] test; really [ keyword '='] keyword */
924924 if (NCH (n ) == 1 ) {
925- if (inkeywords ) {
925+ if (* pkeywords != NULL ) {
926926 com_error (c , SyntaxError ,
927927 "non-keyword arg after keyword arg" );
928928 }
929929 else {
930930 com_node (c , CHILD (n , 0 ));
931931 }
932- return 0 ;
932+ return ;
933933 }
934934 m = n ;
935935 do {
@@ -940,15 +940,22 @@ com_argument(c, n, inkeywords)
940940 }
941941 else {
942942 object * v = newstringobject (STR (m ));
943- if (v == NULL )
943+ if (v != NULL && * pkeywords == NULL )
944+ * pkeywords = newdictobject ();
945+ if (v == NULL || * pkeywords == NULL )
944946 c -> c_errors ++ ;
945947 else {
948+ if (dict2lookup (* pkeywords , v ) != NULL )
949+ com_error (c , SyntaxError ,
950+ "duplicate keyword argument" );
951+ else
952+ if (dict2insert (* pkeywords , v , v ) != 0 )
953+ c -> c_errors ++ ;
946954 com_addoparg (c , LOAD_CONST , com_addconst (c , v ));
947955 DECREF (v );
948956 }
949957 }
950958 com_node (c , CHILD (n , 2 ));
951- return 1 ;
952959}
953960
954961static void
@@ -960,18 +967,19 @@ com_call_function(c, n)
960967 com_addoparg (c , CALL_FUNCTION , 0 );
961968 }
962969 else {
963- int inkeywords , i , na , nk ;
970+ object * keywords = NULL ;
971+ int i , na , nk ;
964972 REQ (n , arglist );
965- inkeywords = 0 ;
966973 na = 0 ;
967974 nk = 0 ;
968975 for (i = 0 ; i < NCH (n ); i += 2 ) {
969- inkeywords = com_argument (c , CHILD (n , i ), inkeywords );
970- if (! inkeywords )
976+ com_argument (c , CHILD (n , i ), & keywords );
977+ if (keywords == NULL )
971978 na ++ ;
972979 else
973980 nk ++ ;
974981 }
982+ XDECREF (keywords );
975983 if (na > 255 || nk > 255 ) {
976984 com_error (c , SyntaxError , "more than 255 arguments" );
977985 }
0 commit comments