[Python-checkins] python/dist/src/Python symtable.c, 2.10.8.19, 2.10.8.20

nnorwitz at projects.sourceforge.net nnorwitz at projects.sourceforge.net
Tue Jan 27 11:36:32 EST 2004


Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21985/Python
Modified Files:
 Tag: ast-branch
	symtable.c 
Log Message:
Cleanup a bit and add some error checking
Index: symtable.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/symtable.c,v
retrieving revision 2.10.8.19
retrieving revision 2.10.8.20
diff -C2 -d -r2.10.8.19 -r2.10.8.20
*** symtable.c	24 Jan 2004 19:43:46 -0000	2.10.8.19
--- symtable.c	27 Jan 2004 16:36:30 -0000	2.10.8.20
***************
*** 47,57 ****
 	ste->ste_lineno = lineno;
 
! 	if (st->st_cur == NULL)
! 		ste->ste_nested = 0;
! 	else if (st->st_cur->ste_nested 
! 		 || st->st_cur->ste_type == FunctionBlock)
 		ste->ste_nested = 1;
- 	else
- 		ste->ste_nested = 0;
 	ste->ste_child_free = 0;
 	ste->ste_generator = 0;
--- 47,55 ----
 	ste->ste_lineno = lineno;
 
! 	ste->ste_nested = 0;
! 	if (st->st_cur != NULL &&
! 	 (st->st_cur->ste_nested ||
! 	 st->st_cur->ste_type == FunctionBlock))
 		ste->ste_nested = 1;
 	ste->ste_child_free = 0;
 	ste->ste_generator = 0;
***************
*** 193,196 ****
--- 191,196 ----
 {
 	struct symtable *st = symtable_new();
+ 	asdl_seq *seq;
+ 	int i;
 
 	if (st == NULL)
***************
*** 203,226 ****
 	/* Any other top-level initialization? */
 	switch (mod->kind) {
! 	case Module_kind: {
! 		int i;
! 		asdl_seq *seq = mod->v.Module.body;
 		for (i = 0; i < asdl_seq_LEN(seq); i++)
 			if (!symtable_visit_stmt(st, asdl_seq_GET(seq, i)))
 				goto error;
 		break;
- 	}
 	case Expression_kind: 
 		if (!symtable_visit_expr(st, mod->v.Expression.body))
 			goto error;
 		break;
! 	case Interactive_kind: {
! 		int i;
! 		asdl_seq *seq = mod->v.Interactive.body;
 		for (i = 0; i < asdl_seq_LEN(seq); i++)
 			if (!symtable_visit_stmt(st, asdl_seq_GET(seq, i)))
 				goto error;
 		break;
- 	}
 	case Suite_kind:
 		PyErr_SetString(PyExc_RuntimeError,
--- 203,222 ----
 	/* Any other top-level initialization? */
 	switch (mod->kind) {
! 	case Module_kind:
! 		seq = mod->v.Module.body;
 		for (i = 0; i < asdl_seq_LEN(seq); i++)
 			if (!symtable_visit_stmt(st, asdl_seq_GET(seq, i)))
 				goto error;
 		break;
 	case Expression_kind: 
 		if (!symtable_visit_expr(st, mod->v.Expression.body))
 			goto error;
 		break;
! 	case Interactive_kind:
! 		seq = mod->v.Interactive.body;
 		for (i = 0; i < asdl_seq_LEN(seq); i++)
 			if (!symtable_visit_stmt(st, asdl_seq_GET(seq, i)))
 				goto error;
 		break;
 	case Suite_kind:
 		PyErr_SetString(PyExc_RuntimeError,
***************
*** 229,235 ****
 	}
 	symtable_exit_block(st, (void *)mod);
! 	if (!symtable_analyze(st))
! 	 goto error;
! 	return st;
 error:
 	PySymtable_Free(st);
--- 225,230 ----
 	}
 	symtable_exit_block(st, (void *)mod);
! 	if (symtable_analyze(st))
! 		return st;
 error:
 	PySymtable_Free(st);
***************
*** 270,283 ****
 PyST_GetScope(PySTEntryObject *ste, PyObject *name)
 {
! 	PyObject *v;
! 	int flags;
! 
! 	v = PyDict_GetItem(ste->ste_symbols, name);
 	if (!v)
 		return 0;
 	assert(PyInt_Check(v));
! 	flags = PyInt_AS_LONG(v);
! 	flags = (flags >> SCOPE_OFF) & SCOPE_MASK;
! 	return flags;
 }
 
--- 265,273 ----
 PyST_GetScope(PySTEntryObject *ste, PyObject *name)
 {
! 	PyObject *v = PyDict_GetItem(ste->ste_symbols, name);
 	if (!v)
 		return 0;
 	assert(PyInt_Check(v));
! 	return (PyInt_AS_LONG(v) >> SCOPE_OFF) & SCOPE_MASK;
 }
 
***************
*** 376,380 ****
 */
 
! int
 analyze_cells(PyObject *scope, PyObject *free)
 {
--- 366,370 ----
 */
 
! static int
 analyze_cells(PyObject *scope, PyObject *free)
 {
***************
*** 573,576 ****
--- 563,568 ----
 	 val = flag;
 	o = PyInt_FromLong(val);
+ if (o == NULL)
+ return 0;
 	if (PyDict_SetItem(dict, name, o) < 0) {
 		Py_DECREF(o);
***************
*** 585,594 ****
 		/* XXX need to update DEF_GLOBAL for other flags too;
 		 perhaps only DEF_FREE_GLOBAL */
 		if ((o = PyDict_GetItem(st->st_global, name))) {
! 			val = PyInt_AS_LONG(o);
! 			val |= flag;
! 		} else
! 			val = flag;
 		o = PyInt_FromLong(val);
 		if (PyDict_SetItem(st->st_global, name, o) < 0) {
 			Py_DECREF(o);
--- 577,587 ----
 		/* XXX need to update DEF_GLOBAL for other flags too;
 		 perhaps only DEF_FREE_GLOBAL */
+ 		val = flag;
 		if ((o = PyDict_GetItem(st->st_global, name))) {
! 			val |= PyInt_AS_LONG(o);
! 		}
 		o = PyInt_FromLong(val);
+ 		if (o == NULL)
+ 			return 0;
 		if (PyDict_SetItem(st->st_global, name, o) < 0) {
 			Py_DECREF(o);
***************
*** 899,903 ****
 	*/
 	if (a->args && !symtable_visit_params(st, a->args, 1))
! 			return 0;
 	if (a->vararg) {
 		if (!symtable_add_def(st, a->vararg, DEF_PARAM))
--- 892,896 ----
 	*/
 	if (a->args && !symtable_visit_params(st, a->args, 1))
! 		return 0;
 	if (a->vararg) {
 		if (!symtable_add_def(st, a->vararg, DEF_PARAM))
***************
*** 929,940 ****
 symtable_visit_alias(struct symtable *st, alias_ty a)
 {
! 	if (a->asname) {
! 		if (!symtable_add_def(st, a->asname, DEF_IMPORT))
! 			return 0;
! 	}
! 	else if (!symtable_add_def(st, a->name, DEF_IMPORT))
! 		return 0;
! 
! 	return 1;
 }
 
--- 922,927 ----
 symtable_visit_alias(struct symtable *st, alias_ty a)
 {
! 	PyObject *name = (a->asname == NULL) ? a->name : a->asname;
! 	return symtable_add_def(st, name, DEF_IMPORT);
 }
 


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /