[Python-3000-checkins] r67375 - in python/branches/py3k: Python/ast.c

benjamin.peterson python-3000-checkins at python.org
Tue Nov 25 05:02:29 CET 2008


Author: benjamin.peterson
Date: Tue Nov 25 05:02:28 2008
New Revision: 67375

Log:
Merged revisions 67373 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r67373 | benjamin.peterson | 2008-11-24 21:43:14 -0600 (Mon, 24 Nov 2008) | 2 lines
  
  always check the return value of NEW_IDENTIFIER
........


Modified:
   python/branches/py3k/   (props changed)
   python/branches/py3k/Python/ast.c

Modified: python/branches/py3k/Python/ast.c
==============================================================================
--- python/branches/py3k/Python/ast.c	(original)
+++ python/branches/py3k/Python/ast.c	Tue Nov 25 05:02:28 2008
@@ -51,6 +51,8 @@
 new_identifier(const char* n, PyArena *arena)
 {
     PyObject* id = PyUnicode_DecodeUTF8(n, strlen(n), NULL);
+    if (!id)
+        return NULL;
     Py_UNICODE *u = PyUnicode_AS_UNICODE(id);
     /* Check whether there are non-ASCII characters in the
        identifier; if so, normalize to NFKC. */
@@ -826,7 +828,6 @@
                 if (!arg)
                     goto error;
                 asdl_seq_SET(posargs, k++, arg);
-
                 i += 2; /* the name and the comma */
                 break;
             case STAR:
@@ -846,6 +847,8 @@
                 }
                 else {
                     vararg = NEW_IDENTIFIER(CHILD(ch, 0));
+                    if (!vararg)
+                        return NULL;
                     if (NCH(ch) > 1) {
                         /* there is an annotation on the vararg */
                         varargannotation = ast_for_expr(c, CHILD(ch, 2));
@@ -869,6 +872,8 @@
                     /* there is an annotation on the kwarg */
                     kwargannotation = ast_for_expr(c, CHILD(ch, 2));
                 }
+                if (!kwarg)
+                    goto error;
                 i += 3;
                 break;
             default:
@@ -1311,10 +1316,14 @@
     int bytesmode = 0;
     
     switch (TYPE(ch)) {
-    case NAME:
+    case NAME: {
         /* All names start in Load context, but may later be
            changed. */
-        return Name(NEW_IDENTIFIER(ch), Load, LINENO(n), n->n_col_offset, c->c_arena);
+        PyObject *name = NEW_IDENTIFIER(ch);
+        if (!name)
+            return NULL;
+        return Name(name, Load, LINENO(n), n->n_col_offset, c->c_arena);
+    }
     case STRING: {
         PyObject *str = parsestrplus(c, n, &bytesmode);
         if (!str) {
@@ -1589,7 +1598,10 @@
             return ast_for_call(c, CHILD(n, 1), left_expr);
     }
     else if (TYPE(CHILD(n, 0)) == DOT ) {
-        return Attribute(left_expr, NEW_IDENTIFIER(CHILD(n, 1)), Load,
+        PyObject *attr_id = NEW_IDENTIFIER(CHILD(n, 1));
+        if (!attr_id)
+            return NULL;
+        return Attribute(left_expr, attr_id, Load,
                          LINENO(n), n->n_col_offset, c->c_arena);
     }
     else {
@@ -2275,7 +2287,7 @@
       dotted_as_name: dotted_name ['as' NAME]
       dotted_name: NAME ('.' NAME)*
     */
-    PyObject *str;
+    PyObject *str, *name;
 
  loop:
     switch (TYPE(n)) {
@@ -2283,8 +2295,13 @@
             str = NULL;
             if (NCH(n) == 3) {
                 str = NEW_IDENTIFIER(CHILD(n, 2));
+                if (!str)
+                    return NULL;
             }
-            return alias(NEW_IDENTIFIER(CHILD(n, 0)), str, c->c_arena);
+            name = NEW_IDENTIFIER(CHILD(n, 0));
+            if (!name)
+                return NULL;
+            return alias(name, str, c->c_arena);
         case dotted_as_name:
             if (NCH(n) == 1) {
                 n = CHILD(n, 0);
@@ -2296,12 +2313,18 @@
                     return NULL;
                 assert(!a->asname);
                 a->asname = NEW_IDENTIFIER(CHILD(n, 2));
+                if (!a->asname)
+                    return NULL;
                 return a;
             }
             break;
         case dotted_name:
-            if (NCH(n) == 1)
-                return alias(NEW_IDENTIFIER(CHILD(n, 0)), NULL, c->c_arena);
+            if (NCH(n) == 1) {
+                name = NEW_IDENTIFIER(CHILD(n, 0));
+                if (!name)
+                    return NULL;
+                return alias(name, NULL, c->c_arena);
+            }
             else {
                 /* Create a string of the form "a.b.c" */
                 int i;
@@ -2974,6 +2997,7 @@
 ast_for_classdef(struct compiling *c, const node *n, asdl_seq *decorator_seq)
 {
     /* classdef: 'class' NAME ['(' arglist ')'] ':' suite */
+    PyObject *classname;
     asdl_seq *s;
     expr_ty call, dummy;
 
@@ -2983,16 +3007,22 @@
         s = ast_for_suite(c, CHILD(n, 3));
         if (!s)
             return NULL;
-        return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), NULL, NULL, NULL, NULL, s,
-                        decorator_seq, LINENO(n), n->n_col_offset, c->c_arena);
+        classname = NEW_IDENTIFIER(CHILD(n, 1));
+        if (!classname)
+            return NULL;
+        return ClassDef(classname, NULL, NULL, NULL, NULL, s, decorator_seq,
+                        LINENO(n), n->n_col_offset, c->c_arena);
     }
 
     if (TYPE(CHILD(n, 3)) == RPAR) { /* class NAME '(' ')' ':' suite */
         s = ast_for_suite(c, CHILD(n,5));
         if (!s)
-                return NULL;
-        return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), NULL, NULL, NULL, NULL, s,
-                        decorator_seq, LINENO(n), n->n_col_offset, c->c_arena);
+            return NULL;
+        classname = NEW_IDENTIFIER(CHILD(n, 1));
+        if (!classname)
+            return NULL;
+        return ClassDef(classname, NULL, NULL, NULL, NULL, s, decorator_seq,
+                        LINENO(n), n->n_col_offset, c->c_arena);
     }
 
     /* class NAME '(' arglist ')' ':' suite */
@@ -3004,9 +3034,11 @@
     s = ast_for_suite(c, CHILD(n, 6));
     if (!s)
         return NULL;
+    classname = NEW_IDENTIFIER(CHILD(n, 1));
+    if (!classname)
+        return NULL;
 
-    return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)),
-                    call->v.Call.args, call->v.Call.keywords,
+    return ClassDef(classname, call->v.Call.args, call->v.Call.keywords,
                     call->v.Call.starargs, call->v.Call.kwargs, s,
                     decorator_seq, LINENO(n), n->n_col_offset, c->c_arena);
 }


More information about the Python-3000-checkins mailing list