[Python-checkins] python/dist/src/Python compile.c,2.259,2.260

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Thu, 15 Aug 2002 19:13:51 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv11705

Modified Files:
	compile.c 
Log Message:
Add warnings for assignment or deletion of variables and attributes
named 'None'.  Still to do: function definition parameter lists, and
function call keyword arguments.


Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.259
retrieving revision 2.260
diff -C2 -d -r2.259 -r2.260
*** compile.c	16 Aug 2002 01:57:32 -0000	2.259
--- compile.c	16 Aug 2002 02:13:49 -0000	2.260
***************
*** 575,578 ****
--- 575,579 ----
  /* Prototype forward declarations */
  
+ static int issue_warning(char *, char *, int);
  static int com_init(struct compiling *, char *);
  static void com_free(struct compiling *);
***************
*** 989,992 ****
--- 990,1010 ----
  }
  
+ static int
+ none_assignment_check(struct compiling *c, char *name, int assigning)
+ {
+ 	if (name[0] == 'N' && strcmp(name, "None") == 0) {
+ 		char *msg;
+ 		if (assigning)
+ 			msg = "assigment to None";
+ 		else
+ 			msg = "deleting None";
+ 		if (issue_warning(msg, c->c_filename, c->c_lineno) < 0) {
+ 			c->c_errors++;
+ 			return -1;
+ 		}
+ 	}
+ 	return 0;
+ }
+ 
  static void
  com_addop_varname(struct compiling *c, int kind, char *name)
***************
*** 998,1001 ****
--- 1016,1026 ----
  	char buffer[MANGLE_LEN];
  
+ 	if (kind != VAR_LOAD &&
+ 	    none_assignment_check(c, name, kind == VAR_STORE))
+ 	{
+ 		c->c_errors++;
+ 		i = 255;
+ 		goto done;
+ 	}
  	if (_Py_Mangle(c->c_private, name, buffer, sizeof(buffer)))
  		name = buffer;
***************
*** 2490,2493 ****
--- 2515,2520 ----
  com_assign_attr(struct compiling *c, node *n, int assigning)
  {
+ 	if (none_assignment_check(c, STR(n), assigning))
+ 		return;
  	com_addopname(c, assigning ? STORE_ATTR : DELETE_ATTR, n);
  	com_pop(c, assigning ? 2 : 1);