[Python-checkins] python/dist/src/Python ast.c,1.1.2.42,1.1.2.43

nnorwitz at users.sourceforge.net nnorwitz at users.sourceforge.net
Fri Jan 23 11:04:49 EST 2004


Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28991/Python

Modified Files:
      Tag: ast-branch
	ast.c 
Log Message:
Fix mem leak on error, refactor/simplify code for exec stmt

Index: ast.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/ast.c,v
retrieving revision 1.1.2.42
retrieving revision 1.1.2.43
diff -C2 -d -r1.1.2.42 -r1.1.2.43
*** ast.c	23 Jan 2004 04:22:45 -0000	1.1.2.42
--- ast.c	23 Jan 2004 16:03:25 -0000	1.1.2.43
***************
*** 1624,1627 ****
--- 1624,1628 ----
              if (!import_alias) {
                  asdl_seq_free(aliases);
+                 free(mod);
                  return NULL;
              }
***************
*** 1664,1706 ****
  ast_for_exec_stmt(const node *n)
  {
      /* exec_stmt: 'exec' expr ['in' test [',' test]] */
      REQ(n, exec_stmt);
!     if (NCH(n) == 2) {
!         expr_ty expression = ast_for_expr(CHILD(n, 1));
!         if (!expression)
              return NULL;
- 	return Exec(expression, NULL, NULL, LINENO(n));
      }
!     else if (NCH(n) == 4) {
!         expr_ty expr1, expr2;
! 
!         expr1 = ast_for_expr(CHILD(n, 1));
!         if (!expr1)
!             return NULL;
!         expr2 = ast_for_expr(CHILD(n, 3));
!         if (!expr2)
              return NULL;
- 
- 	return Exec(expr1, expr2, NULL, LINENO(n));
      }
-     else if (NCH(n) == 6) {
-         expr_ty expr1, expr2, expr3;
- 
-         expr1 = ast_for_expr(CHILD(n, 1));
-         if (!expr1)
-             return NULL;
-         expr2 = ast_for_expr(CHILD(n, 3));
-         if (!expr2)
-             return NULL;
-         expr3 = ast_for_expr(CHILD(n, 5));
-         if (!expr3)
-             return NULL;
  
! 	return Exec(expr1, expr2, expr3, LINENO(n));
!     }
!     PyErr_Format(PyExc_Exception,
!                  "poorly formed 'exec' statement: %d parts to statement",
!                  NCH(n));
!     return NULL;
  }
  
--- 1665,1694 ----
  ast_for_exec_stmt(const node *n)
  {
+     expr_ty expr1, globals = NULL, locals = NULL;
+     int n_children = NCH(n);
+     if (n_children != 2 && n_children != 4 && n_children != 6) {
+         PyErr_Format(PyExc_Exception,
+                      "poorly formed 'exec' statement: %d parts to statement",
+                      n_children);
+         return NULL;
+     }
+ 
      /* exec_stmt: 'exec' expr ['in' test [',' test]] */
      REQ(n, exec_stmt);
!     expr1 = ast_for_expr(CHILD(n, 1));
!     if (!expr1)
!         return NULL;
!     if (n_children >= 4) {
!         globals = ast_for_expr(CHILD(n, 3));
!         if (!globals)
              return NULL;
      }
!     if (n_children == 6) {
!         locals = ast_for_expr(CHILD(n, 5));
!         if (!locals)
              return NULL;
      }
  
!     return Exec(expr1, globals, locals, LINENO(n));
  }
  




More information about the Python-checkins mailing list