Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(276460)

Delta Between Two Patch Sets: Modules/parsermodule.c

Issue 11619: On Windows, don't encode filenames in the import machinery
Left Patch Set: Created 8 years, 4 months ago
Right Patch Set: Created 5 years, 12 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Include/warnings.h ('k') | Modules/symtablemodule.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* parsermodule.c 1 /* parsermodule.c
2 * 2 *
3 * Copyright 1995-1996 by Fred L. Drake, Jr. and Virginia Polytechnic 3 * Copyright 1995-1996 by Fred L. Drake, Jr. and Virginia Polytechnic
4 * Institute and State University, Blacksburg, Virginia, USA. 4 * Institute and State University, Blacksburg, Virginia, USA.
5 * Portions copyright 1991-1995 by Stichting Mathematisch Centrum, 5 * Portions copyright 1991-1995 by Stichting Mathematisch Centrum,
6 * Amsterdam, The Netherlands. Copying is permitted under the terms 6 * Amsterdam, The Netherlands. Copying is permitted under the terms
7 * associated with the main Python distribution, with the additional 7 * associated with the main Python distribution, with the additional
8 * restriction that this additional notice be included and maintained 8 * restriction that this additional notice be included and maintained
9 * on all distributed copies. 9 * on all distributed copies.
10 * 10 *
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 */ 76 */
77 77
78 78
79 static PyObject* 79 static PyObject*
80 node2tuple(node *n, /* node to convert */ 80 node2tuple(node *n, /* node to convert */
81 SeqMaker mkseq, /* create sequence */ 81 SeqMaker mkseq, /* create sequence */
82 SeqInserter addelem, /* func. to add elem. in seq. */ 82 SeqInserter addelem, /* func. to add elem. in seq. */
83 int lineno, /* include line numbers? */ 83 int lineno, /* include line numbers? */
84 int col_offset) /* include column offsets? */ 84 int col_offset) /* include column offsets? */
85 { 85 {
86 PyObject *result = NULL, *w;
87
86 if (n == NULL) { 88 if (n == NULL) {
87 Py_INCREF(Py_None); 89 Py_INCREF(Py_None);
88 return (Py_None); 90 return Py_None;
89 } 91 }
92
90 if (ISNONTERMINAL(TYPE(n))) { 93 if (ISNONTERMINAL(TYPE(n))) {
91 int i; 94 int i;
92 PyObject *v; 95
93 PyObject *w; 96 result = mkseq(1 + NCH(n) + (TYPE(n) == encoding_decl));
94 97 if (result == NULL)
95 v = mkseq(1 + NCH(n) + (TYPE(n) == encoding_decl)); 98 goto error;
96 if (v == NULL) 99
97 return (v);
98 w = PyLong_FromLong(TYPE(n)); 100 w = PyLong_FromLong(TYPE(n));
99 if (w == NULL) { 101 if (w == NULL)
100 Py_DECREF(v); 102 goto error;
101 return ((PyObject*) NULL); 103 (void) addelem(result, 0, w);
102 } 104
103 (void) addelem(v, 0, w);
104 for (i = 0; i < NCH(n); i++) { 105 for (i = 0; i < NCH(n); i++) {
105 w = node2tuple(CHILD(n, i), mkseq, addelem, lineno, col_offset); 106 w = node2tuple(CHILD(n, i), mkseq, addelem, lineno, col_offset);
106 if (w == NULL) { 107 if (w == NULL)
107 Py_DECREF(v); 108 goto error;
108 return ((PyObject*) NULL); 109 (void) addelem(result, i+1, w);
109 } 110 }
110 (void) addelem(v, i+1, w); 111
111 } 112 if (TYPE(n) == encoding_decl) {
112 113 w = PyUnicode_FromString(STR(n));
113 if (TYPE(n) == encoding_decl) 114 if (w == NULL)
114 (void) addelem(v, i+1, PyUnicode_FromString(STR(n))); 115 goto error;
115 return (v); 116 (void) addelem(result, i+1, w);
117 }
116 } 118 }
117 else if (ISTERMINAL(TYPE(n))) { 119 else if (ISTERMINAL(TYPE(n))) {
118 PyObject *result = mkseq(2 + lineno + col_offset); 120 result = mkseq(2 + lineno + col_offset);
119 if (result != NULL) { 121 if (result == NULL)
120 (void) addelem(result, 0, PyLong_FromLong(TYPE(n))); 122 goto error;
121 (void) addelem(result, 1, PyUnicode_FromString(STR(n))); 123
122 if (lineno == 1) 124 w = PyLong_FromLong(TYPE(n));
123 (void) addelem(result, 2, PyLong_FromLong(n->n_lineno)); 125 if (w == NULL)
124 if (col_offset == 1) 126 goto error;
125 (void) addelem(result, 3, PyLong_FromLong(n->n_col_offset)); 127 (void) addelem(result, 0, w);
126 } 128
127 return (result); 129 w = PyUnicode_FromString(STR(n));
130 if (w == NULL)
131 goto error;
132 (void) addelem(result, 1, w);
133
134 if (lineno == 1) {
135 w = PyLong_FromLong(n->n_lineno);
136 if (w == NULL)
137 goto error;
138 (void) addelem(result, 2, w);
139 }
140
141 if (col_offset == 1) {
142 w = PyLong_FromLong(n->n_col_offset);
143 if (w == NULL)
144 goto error;
145 (void) addelem(result, 3, w);
146 }
128 } 147 }
129 else { 148 else {
130 PyErr_SetString(PyExc_SystemError, 149 PyErr_SetString(PyExc_SystemError,
131 "unrecognized parse tree node type"); 150 "unrecognized parse tree node type");
132 return ((PyObject*) NULL); 151 return ((PyObject*) NULL);
133 } 152 }
153 return result;
154
155 error:
156 Py_XDECREF(result);
157 return NULL;
134 } 158 }
135 /* 159 /*
136 * End of material copyrighted by Stichting Mathematisch Centrum. 160 * End of material copyrighted by Stichting Mathematisch Centrum.
137 */ 161 */
138 162
139 163
140 164
141 /* There are two types of intermediate objects we're interested in: 165 /* There are two types of intermediate objects we're interested in:
142 * 'eval' and 'exec' types. These constants can be used in the st_type 166 * 'eval' and 'exec' types. These constants can be used in the st_type
143 * field of the object type to identify which any given object represents. 167 * field of the object type to identify which any given object represents.
(...skipping 16 matching lines...) Expand all
160 184
161 typedef struct { 185 typedef struct {
162 PyObject_HEAD /* standard object header */ 186 PyObject_HEAD /* standard object header */
163 node* st_node; /* the node* returned by the parser */ 187 node* st_node; /* the node* returned by the parser */
164 int st_type; /* EXPR or SUITE ? */ 188 int st_type; /* EXPR or SUITE ? */
165 PyCompilerFlags st_flags; /* Parser and compiler flags */ 189 PyCompilerFlags st_flags; /* Parser and compiler flags */
166 } PyST_Object; 190 } PyST_Object;
167 191
168 192
169 static void parser_free(PyST_Object *st); 193 static void parser_free(PyST_Object *st);
194 static PyObject* parser_sizeof(PyST_Object *, void *);
170 static PyObject* parser_richcompare(PyObject *left, PyObject *right, int op); 195 static PyObject* parser_richcompare(PyObject *left, PyObject *right, int op);
171 static PyObject* parser_compilest(PyST_Object *, PyObject *, PyObject *); 196 static PyObject* parser_compilest(PyST_Object *, PyObject *, PyObject *);
172 static PyObject* parser_isexpr(PyST_Object *, PyObject *, PyObject *); 197 static PyObject* parser_isexpr(PyST_Object *, PyObject *, PyObject *);
173 static PyObject* parser_issuite(PyST_Object *, PyObject *, PyObject *); 198 static PyObject* parser_issuite(PyST_Object *, PyObject *, PyObject *);
174 static PyObject* parser_st2list(PyST_Object *, PyObject *, PyObject *); 199 static PyObject* parser_st2list(PyST_Object *, PyObject *, PyObject *);
175 static PyObject* parser_st2tuple(PyST_Object *, PyObject *, PyObject *); 200 static PyObject* parser_st2tuple(PyST_Object *, PyObject *, PyObject *);
176 201
177 #define PUBLIC_METHOD_TYPE (METH_VARARGS|METH_KEYWORDS) 202 #define PUBLIC_METHOD_TYPE (METH_VARARGS|METH_KEYWORDS)
178 203
179 static PyMethodDef parser_methods[] = { 204 static PyMethodDef parser_methods[] = {
180 {"compile", (PyCFunction)parser_compilest, PUBLIC_METHOD_TYPE, 205 {"compile", (PyCFunction)parser_compilest, PUBLIC_METHOD_TYPE,
181 PyDoc_STR("Compile this ST object into a code object.")}, 206 PyDoc_STR("Compile this ST object into a code object.")},
182 {"isexpr", (PyCFunction)parser_isexpr, PUBLIC_METHOD_TYPE, 207 {"isexpr", (PyCFunction)parser_isexpr, PUBLIC_METHOD_TYPE,
183 PyDoc_STR("Determines if this ST object was created from an expression." )}, 208 PyDoc_STR("Determines if this ST object was created from an expression." )},
184 {"issuite", (PyCFunction)parser_issuite, PUBLIC_METHOD_TYPE, 209 {"issuite", (PyCFunction)parser_issuite, PUBLIC_METHOD_TYPE,
185 PyDoc_STR("Determines if this ST object was created from a suite.")}, 210 PyDoc_STR("Determines if this ST object was created from a suite.")},
186 {"tolist", (PyCFunction)parser_st2list, PUBLIC_METHOD_TYPE, 211 {"tolist", (PyCFunction)parser_st2list, PUBLIC_METHOD_TYPE,
187 PyDoc_STR("Creates a list-tree representation of this ST.")}, 212 PyDoc_STR("Creates a list-tree representation of this ST.")},
188 {"totuple", (PyCFunction)parser_st2tuple, PUBLIC_METHOD_TYPE, 213 {"totuple", (PyCFunction)parser_st2tuple, PUBLIC_METHOD_TYPE,
189 PyDoc_STR("Creates a tuple-tree representation of this ST.")}, 214 PyDoc_STR("Creates a tuple-tree representation of this ST.")},
190 215 {"__sizeof__", (PyCFunction)parser_sizeof, METH_NOARGS,
216 PyDoc_STR("Returns size in memory, in bytes.")},
191 {NULL, NULL, 0, NULL} 217 {NULL, NULL, 0, NULL}
192 }; 218 };
193 219
194 static 220 static
195 PyTypeObject PyST_Type = { 221 PyTypeObject PyST_Type = {
196 PyVarObject_HEAD_INIT(NULL, 0) 222 PyVarObject_HEAD_INIT(NULL, 0)
197 "parser.st", /* tp_name */ 223 "parser.st", /* tp_name */
198 (int) sizeof(PyST_Object), /* tp_basicsize */ 224 (int) sizeof(PyST_Object), /* tp_basicsize */
199 0, /* tp_itemsize */ 225 0, /* tp_itemsize */
200 (destructor)parser_free, /* tp_dealloc */ 226 (destructor)parser_free, /* tp_dealloc */
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 317
292 if (left == right) 318 if (left == right)
293 /* if arguments are identical, they're equal */ 319 /* if arguments are identical, they're equal */
294 result = 0; 320 result = 0;
295 else 321 else
296 result = parser_compare_nodes(((PyST_Object *)left)->st_node, 322 result = parser_compare_nodes(((PyST_Object *)left)->st_node,
297 ((PyST_Object *)right)->st_node); 323 ((PyST_Object *)right)->st_node);
298 324
299 /* Convert return value to a Boolean */ 325 /* Convert return value to a Boolean */
300 switch (op) { 326 switch (op) {
301 case Py_EQ: 327 case Py_EQ:
302 v = TEST_COND(result == 0); 328 v = TEST_COND(result == 0);
303 break; 329 break;
304 case Py_NE: 330 case Py_NE:
305 v = TEST_COND(result != 0); 331 v = TEST_COND(result != 0);
306 break; 332 break;
307 case Py_LE: 333 case Py_LE:
308 v = TEST_COND(result <= 0); 334 v = TEST_COND(result <= 0);
309 break; 335 break;
310 case Py_GE: 336 case Py_GE:
311 v = TEST_COND(result >= 0); 337 v = TEST_COND(result >= 0);
312 break; 338 break;
313 case Py_LT: 339 case Py_LT:
314 v = TEST_COND(result < 0); 340 v = TEST_COND(result < 0);
315 break; 341 break;
316 case Py_GT: 342 case Py_GT:
317 v = TEST_COND(result > 0); 343 v = TEST_COND(result > 0);
318 break; 344 break;
319 default: 345 default:
320 PyErr_BadArgument(); 346 PyErr_BadArgument();
321 return NULL; 347 return NULL;
322 } 348 }
323 finished: 349 finished:
324 Py_INCREF(v); 350 Py_INCREF(v);
325 return v; 351 return v;
326 } 352 }
327 353
328 /* parser_newstobject(node* st) 354 /* parser_newstobject(node* st)
329 * 355 *
(...skipping 24 matching lines...) Expand all
354 * This is called by a del statement that reduces the reference count to 0. 380 * This is called by a del statement that reduces the reference count to 0.
355 * 381 *
356 */ 382 */
357 static void 383 static void
358 parser_free(PyST_Object *st) 384 parser_free(PyST_Object *st)
359 { 385 {
360 PyNode_Free(st->st_node); 386 PyNode_Free(st->st_node);
361 PyObject_Del(st); 387 PyObject_Del(st);
362 } 388 }
363 389
390 static PyObject *
391 parser_sizeof(PyST_Object *st, void *unused)
392 {
393 Py_ssize_t res;
394
395 res = sizeof(PyST_Object) + _PyNode_SizeOf(st->st_node);
396 return PyLong_FromSsize_t(res);
397 }
398
364 399
365 /* parser_st2tuple(PyObject* self, PyObject* args, PyObject* kw) 400 /* parser_st2tuple(PyObject* self, PyObject* args, PyObject* kw)
366 * 401 *
367 * This provides conversion from a node* to a tuple object that can be 402 * This provides conversion from a node* to a tuple object that can be
368 * returned to the Python-level caller. The ST object is not modified. 403 * returned to the Python-level caller. The ST object is not modified.
369 * 404 *
370 */ 405 */
371 static PyObject* 406 static PyObject*
372 parser_st2tuple(PyST_Object *self, PyObject *args, PyObject *kw) 407 parser_st2tuple(PyST_Object *self, PyObject *args, PyObject *kw)
373 { 408 {
374 PyObject *line_option = 0; 409 int line_info = 0;
375 PyObject *col_option = 0; 410 int col_info = 0;
376 PyObject *res = 0; 411 PyObject *res = 0;
377 int ok; 412 int ok;
378 413
379 static char *keywords[] = {"st", "line_info", "col_info", NULL}; 414 static char *keywords[] = {"st", "line_info", "col_info", NULL};
380 415
381 if (self == NULL || PyModule_Check(self)) { 416 if (self == NULL || PyModule_Check(self)) {
382 ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|OO:st2tuple", keywords, 417 ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|pp:st2tuple", keywords,
383 &PyST_Type, &self, &line_option, 418 &PyST_Type, &self, &line_info,
384 &col_option); 419 &col_info);
385 } 420 }
386 else 421 else
387 ok = PyArg_ParseTupleAndKeywords(args, kw, "|OO:totuple", &keywords[1], 422 ok = PyArg_ParseTupleAndKeywords(args, kw, "|pp:totuple", &keywords[1],
388 &line_option, &col_option); 423 &line_info, &col_info);
389 if (ok != 0) { 424 if (ok != 0) {
390 int lineno = 0;
391 int col_offset = 0;
392 if (line_option != NULL) {
393 lineno = (PyObject_IsTrue(line_option) != 0) ? 1 : 0;
394 }
395 if (col_option != NULL) {
396 col_offset = (PyObject_IsTrue(col_option) != 0) ? 1 : 0;
397 }
398 /* 425 /*
399 * Convert ST into a tuple representation. Use Guido's function, 426 * Convert ST into a tuple representation. Use Guido's function,
400 * since it's known to work already. 427 * since it's known to work already.
401 */ 428 */
402 res = node2tuple(((PyST_Object*)self)->st_node, 429 res = node2tuple(((PyST_Object*)self)->st_node,
403 PyTuple_New, PyTuple_SetItem, lineno, col_offset); 430 PyTuple_New, PyTuple_SetItem, line_info, col_info);
404 } 431 }
405 return (res); 432 return (res);
406 } 433 }
407 434
408 435
409 /* parser_st2list(PyObject* self, PyObject* args, PyObject* kw) 436 /* parser_st2list(PyObject* self, PyObject* args, PyObject* kw)
410 * 437 *
411 * This provides conversion from a node* to a list object that can be 438 * This provides conversion from a node* to a list object that can be
412 * returned to the Python-level caller. The ST object is not modified. 439 * returned to the Python-level caller. The ST object is not modified.
413 * 440 *
414 */ 441 */
415 static PyObject* 442 static PyObject*
416 parser_st2list(PyST_Object *self, PyObject *args, PyObject *kw) 443 parser_st2list(PyST_Object *self, PyObject *args, PyObject *kw)
417 { 444 {
418 PyObject *line_option = 0; 445 int line_info = 0;
419 PyObject *col_option = 0; 446 int col_info = 0;
420 PyObject *res = 0; 447 PyObject *res = 0;
421 int ok; 448 int ok;
422 449
423 static char *keywords[] = {"st", "line_info", "col_info", NULL}; 450 static char *keywords[] = {"st", "line_info", "col_info", NULL};
424 451
425 if (self == NULL || PyModule_Check(self)) 452 if (self == NULL || PyModule_Check(self))
426 ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|OO:st2list", keywords, 453 ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|pp:st2list", keywords,
427 &PyST_Type, &self, &line_option, 454 &PyST_Type, &self, &line_info,
428 &col_option); 455 &col_info);
429 else 456 else
430 ok = PyArg_ParseTupleAndKeywords(args, kw, "|OO:tolist", &keywords[1], 457 ok = PyArg_ParseTupleAndKeywords(args, kw, "|pp:tolist", &keywords[1],
431 &line_option, &col_option); 458 &line_info, &col_info);
432 if (ok) { 459 if (ok) {
433 int lineno = 0;
434 int col_offset = 0;
435 if (line_option != 0) {
436 lineno = PyObject_IsTrue(line_option) ? 1 : 0;
437 }
438 if (col_option != NULL) {
439 col_offset = (PyObject_IsTrue(col_option) != 0) ? 1 : 0;
440 }
441 /* 460 /*
442 * Convert ST into a tuple representation. Use Guido's function, 461 * Convert ST into a tuple representation. Use Guido's function,
443 * since it's known to work already. 462 * since it's known to work already.
444 */ 463 */
445 res = node2tuple(self->st_node, 464 res = node2tuple(self->st_node,
446 PyList_New, PyList_SetItem, lineno, col_offset); 465 PyList_New, PyList_SetItem, line_info, col_info);
447 } 466 }
448 return (res); 467 return (res);
449 } 468 }
450 469
451 470
452 /* parser_compilest(PyObject* self, PyObject* args) 471 /* parser_compilest(PyObject* self, PyObject* args)
453 * 472 *
454 * This function creates code objects from the parse tree represented by 473 * This function creates code objects from the parse tree represented by
455 * the passed-in data object. An optional file name is passed in as well. 474 * the passed-in data object. An optional file name is passed in as well.
456 * 475 *
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 &_PyParser_Grammar, 606 &_PyParser_Grammar,
588 (type == PyST_EXPR) 607 (type == PyST_EXPR)
589 ? eval_input : file_input, 608 ? eval_input : file_input,
590 &err, &flags); 609 &err, &flags);
591 610
592 if (n) { 611 if (n) {
593 res = parser_newstobject(n, type); 612 res = parser_newstobject(n, type);
594 if (res) 613 if (res)
595 ((PyST_Object *)res)->st_flags.cf_flags = flags & PyCF_MASK; 614 ((PyST_Object *)res)->st_flags.cf_flags = flags & PyCF_MASK;
596 } 615 }
597 else 616 else {
598 PyParser_SetError(&err); 617 PyParser_SetError(&err);
599 } 618 }
600 PyParser_ClearError(&err); 619 PyParser_ClearError(&err);
620 }
601 return (res); 621 return (res);
602 } 622 }
603 623
604 624
605 /* PyObject* parser_expr(PyObject* self, PyObject* args) 625 /* PyObject* parser_expr(PyObject* self, PyObject* args)
606 * PyObject* parser_suite(PyObject* self, PyObject* args) 626 * PyObject* parser_suite(PyObject* self, PyObject* args)
607 * 627 *
608 * External interfaces to the parser itself. Which is called determines if 628 * External interfaces to the parser itself. Which is called determines if
609 * the parser attempts to recognize an expression ('eval' form) or statement 629 * the parser attempts to recognize an expression ('eval' form) or statement
610 * suite ('exec' form). The real work is done by parser_do_parse() above. 630 * suite ('exec' form). The real work is done by parser_do_parse() above.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 st = parser_newstobject(tree, PyST_SUITE); 726 st = parser_newstobject(tree, PyST_SUITE);
707 else 727 else
708 PyNode_Free(tree); 728 PyNode_Free(tree);
709 } 729 }
710 else { 730 else {
711 /* This is a fragment, at best. */ 731 /* This is a fragment, at best. */
712 PyNode_Free(tree); 732 PyNode_Free(tree);
713 err_string("parse tree does not use a valid start symbol"); 733 err_string("parse tree does not use a valid start symbol");
714 } 734 }
715 } 735 }
716 /* Make sure we throw an exception on all errors. We should never 736 /* Make sure we raise an exception on all errors. We should never
717 * get this, but we'd do well to be sure something is done. 737 * get this, but we'd do well to be sure something is done.
718 */ 738 */
719 if (st == NULL && !PyErr_Occurred()) 739 if (st == NULL && !PyErr_Occurred())
720 err_string("unspecified ST error occurred"); 740 err_string("unspecified ST error occurred");
721 741
722 return st; 742 return st;
723 } 743 }
724 744
725 745
726 /* node* build_node_children() 746 /* node* build_node_children()
727 * 747 *
728 * Iterate across the children of the current non-terminal node and build 748 * Iterate across the children of the current non-terminal node and build
729 * their structures. If successful, return the root of this portion of 749 * their structures. If successful, return the root of this portion of
730 * the tree, otherwise, 0. Any required exception will be specified already, 750 * the tree, otherwise, 0. Any required exception will be specified already,
731 * and no memory will have been deallocated. 751 * and no memory will have been deallocated.
732 * 752 *
733 */ 753 */
734 static node* 754 static node*
735 build_node_children(PyObject *tuple, node *root, int *line_num) 755 build_node_children(PyObject *tuple, node *root, int *line_num)
736 { 756 {
737 Py_ssize_t len = PyObject_Size(tuple); 757 Py_ssize_t len = PyObject_Size(tuple);
738 Py_ssize_t i; 758 Py_ssize_t i;
739 int err; 759 int err;
740 760
741 for (i = 1; i < len; ++i) { 761 for (i = 1; i < len; ++i) {
742 /* elem must always be a sequence, however simple */ 762 /* elem must always be a sequence, however simple */
743 PyObject* elem = PySequence_GetItem(tuple, i); 763 PyObject* elem = PySequence_GetItem(tuple, i);
744 int ok = elem != NULL; 764 int ok = elem != NULL;
745 long type = 0; 765 int type = 0;
746 char *strn = 0; 766 char *strn = 0;
747 767
748 if (ok) 768 if (ok)
749 ok = PySequence_Check(elem); 769 ok = PySequence_Check(elem);
750 if (ok) { 770 if (ok) {
751 PyObject *temp = PySequence_GetItem(elem, 0); 771 PyObject *temp = PySequence_GetItem(elem, 0);
752 if (temp == NULL) 772 if (temp == NULL)
753 ok = 0; 773 ok = 0;
754 else { 774 else {
755 ok = PyLong_Check(temp); 775 ok = PyLong_Check(temp);
756 if (ok) 776 if (ok) {
757 type = PyLong_AS_LONG(temp); 777 type = _PyLong_AsInt(temp);
778 if (type == -1 && PyErr_Occurred()) {
779 Py_DECREF(temp);
780 Py_DECREF(elem);
781 return 0;
782 }
783 }
758 Py_DECREF(temp); 784 Py_DECREF(temp);
759 } 785 }
760 } 786 }
761 if (!ok) { 787 if (!ok) {
762 PyObject *err = Py_BuildValue("os", elem, 788 PyObject *err = Py_BuildValue("os", elem,
763 "Illegal node construct."); 789 "Illegal node construct.");
764 PyErr_SetObject(parser_error, err); 790 PyErr_SetObject(parser_error, err);
765 Py_XDECREF(err); 791 Py_XDECREF(err);
766 Py_XDECREF(elem); 792 Py_XDECREF(elem);
767 return (0); 793 return (0);
(...skipping 15 matching lines...) Expand all
783 "second item in terminal node must be a string," 809 "second item in terminal node must be a string,"
784 " found %s", 810 " found %s",
785 Py_TYPE(temp)->tp_name); 811 Py_TYPE(temp)->tp_name);
786 Py_DECREF(temp); 812 Py_DECREF(temp);
787 Py_DECREF(elem); 813 Py_DECREF(elem);
788 return 0; 814 return 0;
789 } 815 }
790 if (len == 3) { 816 if (len == 3) {
791 PyObject *o = PySequence_GetItem(elem, 2); 817 PyObject *o = PySequence_GetItem(elem, 2);
792 if (o != NULL) { 818 if (o != NULL) {
793 if (PyLong_Check(o)) 819 if (PyLong_Check(o)) {
794 *line_num = PyLong_AS_LONG(o); 820 int num = _PyLong_AsInt(o);
821 if (num == -1 && PyErr_Occurred()) {
822 Py_DECREF(o);
823 Py_DECREF(temp);
824 Py_DECREF(elem);
825 return 0;
826 }
827 *line_num = num;
828 }
795 else { 829 else {
796 PyErr_Format(parser_error, 830 PyErr_Format(parser_error,
797 "third item in terminal node must be an" 831 "third item in terminal node must be an"
798 " integer, found %s", 832 " integer, found %s",
799 Py_TYPE(temp)->tp_name); 833 Py_TYPE(temp)->tp_name);
800 Py_DECREF(o); 834 Py_DECREF(o);
801 Py_DECREF(temp); 835 Py_DECREF(temp);
802 Py_DECREF(elem); 836 Py_DECREF(elem);
803 return 0; 837 return 0;
804 } 838 }
805 Py_DECREF(o); 839 Py_DECREF(o);
806 } 840 }
807 } 841 }
808 temp_str = _PyUnicode_AsStringAndSize(temp, &len); 842 temp_str = _PyUnicode_AsStringAndSize(temp, &len);
809 if (temp_str == NULL) { 843 if (temp_str == NULL) {
810 Py_DECREF(temp); 844 Py_DECREF(temp);
811 Py_XDECREF(elem); 845 Py_XDECREF(elem);
812 return 0; 846 return 0;
813 } 847 }
814 strn = (char *)PyObject_MALLOC(len + 1); 848 strn = (char *)PyObject_MALLOC(len + 1);
815 if (strn != NULL) 849 if (strn == NULL) {
816 (void) memcpy(strn, temp_str, len + 1); 850 Py_DECREF(temp);
851 Py_XDECREF(elem);
852 PyErr_NoMemory();
853 return 0;
854 }
855 (void) memcpy(strn, temp_str, len + 1);
817 Py_DECREF(temp); 856 Py_DECREF(temp);
818 } 857 }
819 else if (!ISNONTERMINAL(type)) { 858 else if (!ISNONTERMINAL(type)) {
820 /* 859 /*
821 * It has to be one or the other; this is an error. 860 * It has to be one or the other; this is an error.
822 * Throw an exception. 861 * Raise an exception.
823 */ 862 */
824 PyObject *err = Py_BuildValue("os", elem, "unknown node type."); 863 PyObject *err = Py_BuildValue("os", elem, "unknown node type.");
825 PyErr_SetObject(parser_error, err); 864 PyErr_SetObject(parser_error, err);
826 Py_XDECREF(err); 865 Py_XDECREF(err);
827 Py_XDECREF(elem); 866 Py_XDECREF(elem);
828 return (0); 867 return (0);
829 } 868 }
830 err = PyNode_AddChild(root, type, strn, *line_num, 0); 869 err = PyNode_AddChild(root, type, strn, *line_num, 0);
831 if (err == E_NOMEM) { 870 if (err == E_NOMEM) {
832 Py_XDECREF(elem); 871 Py_XDECREF(elem);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 node* res = 0; 903 node* res = 0;
865 PyObject *temp = PySequence_GetItem(tuple, 0); 904 PyObject *temp = PySequence_GetItem(tuple, 0);
866 long num = -1; 905 long num = -1;
867 906
868 if (temp != NULL) 907 if (temp != NULL)
869 num = PyLong_AsLong(temp); 908 num = PyLong_AsLong(temp);
870 Py_XDECREF(temp); 909 Py_XDECREF(temp);
871 if (ISTERMINAL(num)) { 910 if (ISTERMINAL(num)) {
872 /* 911 /*
873 * The tuple is simple, but it doesn't start with a start symbol. 912 * The tuple is simple, but it doesn't start with a start symbol.
874 * Throw an exception now and be done with it. 913 * Raise an exception now and be done with it.
875 */ 914 */
876 tuple = Py_BuildValue("os", tuple, 915 tuple = Py_BuildValue("Os", tuple,
877 "Illegal syntax-tree; cannot start with terminal symbol."); 916 "Illegal syntax-tree; cannot start with terminal symbol.");
878 PyErr_SetObject(parser_error, tuple); 917 PyErr_SetObject(parser_error, tuple);
879 Py_XDECREF(tuple); 918 Py_XDECREF(tuple);
880 } 919 }
881 else if (ISNONTERMINAL(num)) { 920 else if (ISNONTERMINAL(num)) {
882 /* 921 /*
883 * Not efficient, but that can be handled later. 922 * Not efficient, but that can be handled later.
884 */ 923 */
885 int line_num = 0; 924 int line_num = 0;
886 PyObject *encoding = NULL; 925 PyObject *encoding = NULL;
(...skipping 15 matching lines...) Expand all
902 Py_ssize_t len; 941 Py_ssize_t len;
903 const char *temp; 942 const char *temp;
904 temp = _PyUnicode_AsStringAndSize(encoding, &len); 943 temp = _PyUnicode_AsStringAndSize(encoding, &len);
905 if (temp == NULL) { 944 if (temp == NULL) {
906 Py_DECREF(res); 945 Py_DECREF(res);
907 Py_DECREF(encoding); 946 Py_DECREF(encoding);
908 Py_DECREF(tuple); 947 Py_DECREF(tuple);
909 return NULL; 948 return NULL;
910 } 949 }
911 res->n_str = (char *)PyObject_MALLOC(len + 1); 950 res->n_str = (char *)PyObject_MALLOC(len + 1);
912 if (res->n_str != NULL && temp != NULL) 951 if (res->n_str == NULL) {
913 (void) memcpy(res->n_str, temp, len + 1); 952 Py_DECREF(res);
953 Py_DECREF(encoding);
954 Py_DECREF(tuple);
955 PyErr_NoMemory();
956 return NULL;
957 }
958 (void) memcpy(res->n_str, temp, len + 1);
914 Py_DECREF(encoding); 959 Py_DECREF(encoding);
915 Py_DECREF(tuple); 960 Py_DECREF(tuple);
916 } 961 }
917 } 962 }
918 } 963 }
919 else { 964 else {
920 /* The tuple is illegal -- if the number is neither TERMINAL nor 965 /* The tuple is illegal -- if the number is neither TERMINAL nor
921 * NONTERMINAL, we can't use it. Not sure the implementation 966 * NONTERMINAL, we can't use it. Not sure the implementation
922 * allows this condition, but the API doesn't preclude it. 967 * allows this condition, but the API doesn't preclude it.
923 */ 968 */
(...skipping 21 matching lines...) Expand all
945 #define validate_indent(ch) validate_terminal(ch, INDENT, (char*)NULL) 990 #define validate_indent(ch) validate_terminal(ch, INDENT, (char*)NULL)
946 #define validate_lparen(ch) validate_terminal(ch, LPAR, "(") 991 #define validate_lparen(ch) validate_terminal(ch, LPAR, "(")
947 #define validate_newline(ch) validate_terminal(ch, NEWLINE, (char*)NULL) 992 #define validate_newline(ch) validate_terminal(ch, NEWLINE, (char*)NULL)
948 #define validate_rparen(ch) validate_terminal(ch, RPAR, ")") 993 #define validate_rparen(ch) validate_terminal(ch, RPAR, ")")
949 #define validate_semi(ch) validate_terminal(ch, SEMI, ";") 994 #define validate_semi(ch) validate_terminal(ch, SEMI, ";")
950 #define validate_star(ch) validate_terminal(ch, STAR, "*") 995 #define validate_star(ch) validate_terminal(ch, STAR, "*")
951 #define validate_vbar(ch) validate_terminal(ch, VBAR, "|") 996 #define validate_vbar(ch) validate_terminal(ch, VBAR, "|")
952 #define validate_doublestar(ch) validate_terminal(ch, DOUBLESTAR, "**") 997 #define validate_doublestar(ch) validate_terminal(ch, DOUBLESTAR, "**")
953 #define validate_dot(ch) validate_terminal(ch, DOT, ".") 998 #define validate_dot(ch) validate_terminal(ch, DOT, ".")
954 #define validate_at(ch) validate_terminal(ch, AT, "@") 999 #define validate_at(ch) validate_terminal(ch, AT, "@")
1000 #define validate_rarrow(ch) validate_terminal(ch, RARROW, "->")
955 #define validate_name(ch, str) validate_terminal(ch, NAME, str) 1001 #define validate_name(ch, str) validate_terminal(ch, NAME, str)
956 1002
957 #define VALIDATER(n) static int validate_##n(node *tree) 1003 #define VALIDATER(n) static int validate_##n(node *tree)
958 1004
959 VALIDATER(node); VALIDATER(small_stmt); 1005 VALIDATER(node); VALIDATER(small_stmt);
960 VALIDATER(class); VALIDATER(node); 1006 VALIDATER(class); VALIDATER(node);
961 VALIDATER(parameters); VALIDATER(suite); 1007 VALIDATER(parameters); VALIDATER(suite);
962 VALIDATER(testlist); VALIDATER(varargslist); 1008 VALIDATER(testlist); VALIDATER(varargslist);
963 VALIDATER(vfpdef); 1009 VALIDATER(vfpdef);
964 VALIDATER(stmt); VALIDATER(simple_stmt); 1010 VALIDATER(stmt); VALIDATER(simple_stmt);
965 VALIDATER(expr_stmt); VALIDATER(power); 1011 VALIDATER(expr_stmt); VALIDATER(power);
966 VALIDATER(del_stmt); 1012 VALIDATER(del_stmt);
967 VALIDATER(return_stmt); VALIDATER(raise_stmt); 1013 VALIDATER(return_stmt); VALIDATER(raise_stmt);
968 VALIDATER(import_stmt); VALIDATER(import_stmt); 1014 VALIDATER(import_stmt); VALIDATER(import_stmt);
969 VALIDATER(import_name); VALIDATER(yield_stmt); 1015 VALIDATER(import_name); VALIDATER(yield_stmt);
970 VALIDATER(global_stmt); VALIDATER(assert_stmt); 1016 VALIDATER(global_stmt); VALIDATER(nonlocal_stmt);
1017 VALIDATER(assert_stmt);
971 VALIDATER(compound_stmt); VALIDATER(test_or_star_expr); 1018 VALIDATER(compound_stmt); VALIDATER(test_or_star_expr);
972 VALIDATER(while); VALIDATER(for); 1019 VALIDATER(while); VALIDATER(for);
973 VALIDATER(try); VALIDATER(except_clause); 1020 VALIDATER(try); VALIDATER(except_clause);
974 VALIDATER(test); VALIDATER(and_test); 1021 VALIDATER(test); VALIDATER(and_test);
975 VALIDATER(not_test); VALIDATER(comparison); 1022 VALIDATER(not_test); VALIDATER(comparison);
976 VALIDATER(comp_op); 1023 VALIDATER(comp_op);
977 VALIDATER(star_expr); VALIDATER(expr); 1024 VALIDATER(star_expr); VALIDATER(expr);
978 VALIDATER(xor_expr); VALIDATER(and_expr); 1025 VALIDATER(xor_expr); VALIDATER(and_expr);
979 VALIDATER(shift_expr); VALIDATER(arith_expr); 1026 VALIDATER(shift_expr); VALIDATER(arith_expr);
980 VALIDATER(term); VALIDATER(factor); 1027 VALIDATER(term); VALIDATER(factor);
981 VALIDATER(atom); VALIDATER(lambdef); 1028 VALIDATER(atom); VALIDATER(lambdef);
982 VALIDATER(trailer); VALIDATER(subscript); 1029 VALIDATER(trailer); VALIDATER(subscript);
983 VALIDATER(subscriptlist); VALIDATER(sliceop); 1030 VALIDATER(subscriptlist); VALIDATER(sliceop);
984 VALIDATER(exprlist); VALIDATER(dictorsetmaker); 1031 VALIDATER(exprlist); VALIDATER(dictorsetmaker);
985 VALIDATER(arglist); VALIDATER(argument); 1032 VALIDATER(arglist); VALIDATER(argument);
986 VALIDATER(comp_for); 1033 VALIDATER(comp_for);
987 VALIDATER(comp_iter); VALIDATER(comp_if); 1034 VALIDATER(comp_iter); VALIDATER(comp_if);
988 VALIDATER(testlist_comp); VALIDATER(yield_expr); 1035 VALIDATER(testlist_comp); VALIDATER(yield_expr);
989 VALIDATER(or_test); 1036 VALIDATER(or_test);
990 VALIDATER(test_nocond); VALIDATER(lambdef_nocond); 1037 VALIDATER(test_nocond); VALIDATER(lambdef_nocond);
1038 VALIDATER(yield_arg);
991 1039
992 #undef VALIDATER 1040 #undef VALIDATER
993 1041
994 #define is_even(n) (((n) & 1) == 0) 1042 #define is_even(n) (((n) & 1) == 0)
995 #define is_odd(n) (((n) & 1) == 1) 1043 #define is_odd(n) (((n) & 1) == 1)
996 1044
997 1045
998 static int 1046 static int
999 validate_ntype(node *n, int t) 1047 validate_ntype(node *n, int t)
1000 { 1048 {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1233 } 1281 }
1234 else if (nch == 3) { 1282 else if (nch == 3) {
1235 return validate_name(CHILD(tree, 0), NULL) && 1283 return validate_name(CHILD(tree, 0), NULL) &&
1236 validate_colon(CHILD(tree, 1)) && 1284 validate_colon(CHILD(tree, 1)) &&
1237 validate_test(CHILD(tree, 2)); 1285 validate_test(CHILD(tree, 2));
1238 } 1286 }
1239 } 1287 }
1240 return 0; 1288 return 0;
1241 } 1289 }
1242 1290
1243 /* '*' vfpdef (',' vfpdef ['=' test])* [',' '**' vfpdef] | '**' vfpdef 1291 /* '*' [vfpdef] (',' vfpdef ['=' test])* [',' '**' vfpdef] | '**' vfpdef
1244 * ..or tfpdef in place of vfpdef. vfpdef: NAME; tfpdef: NAME [':' test] 1292 * ..or tfpdef in place of vfpdef. vfpdef: NAME; tfpdef: NAME [':' test]
1245 */ 1293 */
1246 static int 1294 static int
1247 validate_varargslist_trailer(node *tree, int start) 1295 validate_varargslist_trailer(node *tree, int start)
1248 { 1296 {
1249 int nch = NCH(tree); 1297 int nch = NCH(tree);
1250 int res = 0, i; 1298 int res = 0;
1251 int sym;
1252 1299
1253 if (nch <= start) { 1300 if (nch <= start) {
1254 err_string("expected variable argument trailer for varargslist"); 1301 err_string("expected variable argument trailer for varargslist");
1255 return 0; 1302 return 0;
1256 } 1303 }
1257 sym = TYPE(CHILD(tree, start)); 1304 if (TYPE(CHILD(tree, start)) == STAR) {
1258 if (sym == STAR) {
1259 /* 1305 /*
1260 * '*' vfpdef (',' vfpdef ['=' test])* [',' '**' vfpdef] | '**' vfpdef 1306 * '*' [vfpdef]
1261 */ 1307 */
1262 if (nch-start == 2) 1308 res = validate_star(CHILD(tree, start++));
1263 res = validate_vfpdef(CHILD(tree, start+1)); 1309 if (res && start < nch && (TYPE(CHILD(tree, start)) == vfpdef ||
1264 else if (nch-start == 5 && TYPE(CHILD(tree, start+2)) == COMMA) 1310 TYPE(CHILD(tree, start)) == tfpdef))
1265 res = (validate_vfpdef(CHILD(tree, start+1)) 1311 res = validate_vfpdef(CHILD(tree, start++));
1266 && validate_comma(CHILD(tree, start+2)) 1312 /*
1267 && validate_doublestar(CHILD(tree, start+3)) 1313 * (',' vfpdef ['=' test])*
1268 && validate_vfpdef(CHILD(tree, start+4))); 1314 */
1315 while (res && start + 1 < nch && (
1316 TYPE(CHILD(tree, start + 1)) == vfpdef ||
1317 TYPE(CHILD(tree, start + 1)) == tfpdef)) {
1318 res = (validate_comma(CHILD(tree, start++))
1319 && validate_vfpdef(CHILD(tree, start++)));
1320 if (res && start + 1 < nch && TYPE(CHILD(tree, start)) == EQUAL)
1321 res = (validate_equal(CHILD(tree, start++))
1322 && validate_test(CHILD(tree, start++)));
1323 }
1324 /*
1325 * [',' '**' vfpdef]
1326 */
1327 if (res && start + 2 < nch && TYPE(CHILD(tree, start+1)) == DOUBLESTAR)
1328 res = (validate_comma(CHILD(tree, start++))
1329 && validate_doublestar(CHILD(tree, start++))
1330 && validate_vfpdef(CHILD(tree, start++)));
1331 }
1332 else if (TYPE(CHILD(tree, start)) == DOUBLESTAR) {
1333 /*
1334 * '**' vfpdef
1335 */
1336 if (start + 1 < nch)
1337 res = (validate_doublestar(CHILD(tree, start++))
1338 && validate_vfpdef(CHILD(tree, start++)));
1269 else { 1339 else {
1270 /* skip over vfpdef (',' vfpdef ['=' test])* */ 1340 res = 0;
1271 i = start + 1; 1341 err_string("expected vfpdef after ** in varargslist trailer");
1272 if (TYPE(CHILD(tree, i)) == vfpdef || 1342 }
1273 TYPE(CHILD(tree, i)) == tfpdef) { /* skip over vfpdef or tfpdef */ 1343 }
1274 i += 1; 1344 else {
1275 } 1345 res = 0;
1276 while (res && i+1 < nch) { /* validate (',' vfpdef ['=' test])* */ 1346 err_string("expected * or ** in varargslist trailer");
1277 res = validate_comma(CHILD(tree, i)); 1347 }
1278 if (TYPE(CHILD(tree, i+1)) == DOUBLESTAR) 1348
1279 break; 1349 if (res && start != nch) {
1280 res = res && validate_vfpdef(CHILD(tree, i+1)); 1350 res = 0;
1281 if (res && i+2 < nch && TYPE(CHILD(tree, i+2)) == EQUAL) { 1351 err_string("unexpected extra children in varargslist trailer");
1282 res = res && (i+3 < nch) 1352 }
1283 && validate_test(CHILD(tree, i+3));
1284 i += 4;
1285 }
1286 else {
1287 i += 2;
1288 }
1289 }
1290 /* [',' '**' vfpdef] */
1291 if (res && i+1 < nch && TYPE(CHILD(tree, i+1)) == DOUBLESTAR) {
1292 res = validate_vfpdef(CHILD(tree, i+2));
1293 }
1294 }
1295 }
1296 else if (sym == DOUBLESTAR) {
1297 /*
1298 * '**' NAME
1299 */
1300 if (nch-start == 2)
1301 res = validate_vfpdef(CHILD(tree, start+1));
1302 }
1303 if (!res)
1304 err_string("illegal variable argument trailer for varargslist");
1305 return res; 1353 return res;
1306 } 1354 }
1307 1355
1308 1356
1309 /* validate_varargslist() 1357 /* validate_varargslist()
1310 * 1358 *
1311 * Validate typedargslist or varargslist. 1359 * Validate typedargslist or varargslist.
1312 * 1360 *
1313 * typedargslist: ((tfpdef ['=' test] ',')* 1361 * typedargslist: ((tfpdef ['=' test] ',')*
1314 * ('*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef] | 1362 * ('*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef] |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1483 1531
1484 if (res) { 1532 if (res) {
1485 int ntype = TYPE(CHILD(tree, 0)); 1533 int ntype = TYPE(CHILD(tree, 0));
1486 1534
1487 if ( (ntype == expr_stmt) 1535 if ( (ntype == expr_stmt)
1488 || (ntype == del_stmt) 1536 || (ntype == del_stmt)
1489 || (ntype == pass_stmt) 1537 || (ntype == pass_stmt)
1490 || (ntype == flow_stmt) 1538 || (ntype == flow_stmt)
1491 || (ntype == import_stmt) 1539 || (ntype == import_stmt)
1492 || (ntype == global_stmt) 1540 || (ntype == global_stmt)
1541 || (ntype == nonlocal_stmt)
1493 || (ntype == assert_stmt)) 1542 || (ntype == assert_stmt))
1494 res = validate_node(CHILD(tree, 0)); 1543 res = validate_node(CHILD(tree, 0));
1495 else { 1544 else {
1496 res = 0; 1545 res = 0;
1497 err_string("illegal small_stmt child type"); 1546 err_string("illegal small_stmt child type");
1498 } 1547 }
1499 } 1548 }
1500 else if (nch == 1) { 1549 else if (nch == 1) {
1501 res = 0; 1550 res = 0;
1502 PyErr_Format(parser_error, 1551 PyErr_Format(parser_error,
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1612 && ((nch == 1) || (nch == 2)) 1661 && ((nch == 1) || (nch == 2))
1613 && validate_name(CHILD(tree, 0), "return")); 1662 && validate_name(CHILD(tree, 0), "return"));
1614 1663
1615 if (res && (nch == 2)) 1664 if (res && (nch == 2))
1616 res = validate_testlist(CHILD(tree, 1)); 1665 res = validate_testlist(CHILD(tree, 1));
1617 1666
1618 return (res); 1667 return (res);
1619 } 1668 }
1620 1669
1621 1670
1671 /*
1672 * raise_stmt:
1673 *
1674 * 'raise' [test ['from' test]]
1675 */
1622 static int 1676 static int
1623 validate_raise_stmt(node *tree) 1677 validate_raise_stmt(node *tree)
1624 { 1678 {
1625 int nch = NCH(tree); 1679 int nch = NCH(tree);
1626 int res = (validate_ntype(tree, raise_stmt) 1680 int res = (validate_ntype(tree, raise_stmt)
1627 && ((nch == 1) || (nch == 2) || (nch == 4) || (nch == 6))); 1681 && ((nch == 1) || (nch == 2) || (nch == 4)));
1682
1683 if (!res && !PyErr_Occurred())
1684 (void) validate_numnodes(tree, 2, "raise");
1628 1685
1629 if (res) { 1686 if (res) {
1630 res = validate_name(CHILD(tree, 0), "raise"); 1687 res = validate_name(CHILD(tree, 0), "raise");
1631 if (res && (nch >= 2)) 1688 if (res && (nch >= 2))
1632 res = validate_test(CHILD(tree, 1)); 1689 res = validate_test(CHILD(tree, 1));
1633 if (res && nch > 2) { 1690 if (res && (nch == 4)) {
1634 res = (validate_comma(CHILD(tree, 2)) 1691 res = (validate_name(CHILD(tree, 2), "from")
1635 && validate_test(CHILD(tree, 3))); 1692 && validate_test(CHILD(tree, 3)));
1636 if (res && (nch > 4)) 1693 }
1637 res = (validate_comma(CHILD(tree, 4)) 1694 }
1638 && validate_test(CHILD(tree, 5))); 1695 return (res);
1639 } 1696 }
1640 } 1697
1641 else 1698
1642 (void) validate_numnodes(tree, 2, "raise"); 1699 /* yield_expr: 'yield' [yield_arg]
1643 if (res && (nch == 4))
1644 res = (validate_comma(CHILD(tree, 2))
1645 && validate_test(CHILD(tree, 3)));
1646
1647 return (res);
1648 }
1649
1650
1651 /* yield_expr: 'yield' [testlist]
1652 */ 1700 */
1653 static int 1701 static int
1654 validate_yield_expr(node *tree) 1702 validate_yield_expr(node *tree)
1655 { 1703 {
1656 int nch = NCH(tree); 1704 int nch = NCH(tree);
1657 int res = (validate_ntype(tree, yield_expr) 1705 if (nch < 1 || nch > 2)
1658 && ((nch == 1) || (nch == 2)) 1706 return 0;
1659 && validate_name(CHILD(tree, 0), "yield")); 1707 if (!validate_ntype(tree, yield_expr))
1660 1708 return 0;
1661 if (res && (nch == 2)) 1709 if (!validate_name(CHILD(tree, 0), "yield"))
1662 res = validate_testlist(CHILD(tree, 1)); 1710 return 0;
1663 1711 if (nch == 2) {
1664 return (res); 1712 if (!validate_yield_arg(CHILD(tree, 1)))
1665 } 1713 return 0;
1666 1714 }
1715 return 1;
1716 }
1717
1718 /* yield_arg: 'from' test | testlist
1719 */
1720 static int
1721 validate_yield_arg(node *tree)
1722 {
1723 int nch = NCH(tree);
1724 if (!validate_ntype(tree, yield_arg))
1725 return 0;
1726 switch (nch) {
1727 case 1:
1728 if (!validate_testlist(CHILD(tree, nch - 1)))
1729 return 0;
1730 break;
1731 case 2:
1732 if (!validate_name(CHILD(tree, 0), "from"))
1733 return 0;
1734 if (!validate_test(CHILD(tree, 1)))
1735 return 0;
1736 break;
1737 default:
1738 return 0;
1739 }
1740 return 1;
1741 }
1667 1742
1668 /* yield_stmt: yield_expr 1743 /* yield_stmt: yield_expr
1669 */ 1744 */
1670 static int 1745 static int
1671 validate_yield_stmt(node *tree) 1746 validate_yield_stmt(node *tree)
1672 { 1747 {
1673 return (validate_ntype(tree, yield_stmt) 1748 return (validate_ntype(tree, yield_stmt)
1674 && validate_numnodes(tree, 1, "yield_stmt") 1749 && validate_numnodes(tree, 1, "yield_stmt")
1675 && validate_yield_expr(CHILD(tree, 0))); 1750 && validate_yield_expr(CHILD(tree, 0)));
1676 } 1751 }
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1840 else if (nch == 1) { 1915 else if (nch == 1) {
1841 res = 0; 1916 res = 0;
1842 PyErr_Format(parser_error, 1917 PyErr_Format(parser_error,
1843 "Unrecognized child node of import_stmt: %d.", 1918 "Unrecognized child node of import_stmt: %d.",
1844 TYPE(CHILD(tree, 0))); 1919 TYPE(CHILD(tree, 0)));
1845 } 1920 }
1846 return (res); 1921 return (res);
1847 } 1922 }
1848 1923
1849 1924
1850 1925 /* global_stmt:
1851 1926 *
1927 * 'global' NAME (',' NAME)*
1928 */
1852 static int 1929 static int
1853 validate_global_stmt(node *tree) 1930 validate_global_stmt(node *tree)
1854 { 1931 {
1855 int j; 1932 int j;
1856 int nch = NCH(tree); 1933 int nch = NCH(tree);
1857 int res = (validate_ntype(tree, global_stmt) 1934 int res = (validate_ntype(tree, global_stmt)
1858 && is_even(nch) && (nch >= 2)); 1935 && is_even(nch) && (nch >= 2));
1859 1936
1860 if (!res && !PyErr_Occurred()) 1937 if (!res && !PyErr_Occurred())
1861 err_string("illegal global statement"); 1938 err_string("illegal global statement");
1862 1939
1863 if (res) 1940 if (res)
1864 res = (validate_name(CHILD(tree, 0), "global") 1941 res = (validate_name(CHILD(tree, 0), "global")
1865 && validate_ntype(CHILD(tree, 1), NAME)); 1942 && validate_ntype(CHILD(tree, 1), NAME));
1866 for (j = 2; res && (j < nch); j += 2) 1943 for (j = 2; res && (j < nch); j += 2)
1867 res = (validate_comma(CHILD(tree, j)) 1944 res = (validate_comma(CHILD(tree, j))
1868 && validate_ntype(CHILD(tree, j + 1), NAME)); 1945 && validate_ntype(CHILD(tree, j + 1), NAME));
1869 1946
1870 return (res); 1947 return (res);
1871 } 1948 }
1872 1949
1950 /* nonlocal_stmt:
1951 *
1952 * 'nonlocal' NAME (',' NAME)*
1953 */
1954 static int
1955 validate_nonlocal_stmt(node *tree)
1956 {
1957 int j;
1958 int nch = NCH(tree);
1959 int res = (validate_ntype(tree, nonlocal_stmt)
1960 && is_even(nch) && (nch >= 2));
1961
1962 if (!res && !PyErr_Occurred())
1963 err_string("illegal nonlocal statement");
1964
1965 if (res)
1966 res = (validate_name(CHILD(tree, 0), "nonlocal")
1967 && validate_ntype(CHILD(tree, 1), NAME));
1968 for (j = 2; res && (j < nch); j += 2)
1969 res = (validate_comma(CHILD(tree, j))
1970 && validate_ntype(CHILD(tree, j + 1), NAME));
1971
1972 return res;
1973 }
1873 1974
1874 /* assert_stmt: 1975 /* assert_stmt:
1875 * 1976 *
1876 * 'assert' test [',' test] 1977 * 'assert' test [',' test]
1877 */ 1978 */
1878 static int 1979 static int
1879 validate_assert_stmt(node *tree) 1980 validate_assert_stmt(node *tree)
1880 { 1981 {
1881 int nch = NCH(tree); 1982 int nch = NCH(tree);
1882 int res = (validate_ntype(tree, assert_stmt) 1983 int res = (validate_ntype(tree, assert_stmt)
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
2125 2226
2126 if (!validate_ntype(tree, comp_op)) 2227 if (!validate_ntype(tree, comp_op))
2127 return (0); 2228 return (0);
2128 if (nch == 1) { 2229 if (nch == 1) {
2129 /* 2230 /*
2130 * Only child will be a terminal with a well-defined symbolic name 2231 * Only child will be a terminal with a well-defined symbolic name
2131 * or a NAME with a string of either 'is' or 'in' 2232 * or a NAME with a string of either 'is' or 'in'
2132 */ 2233 */
2133 tree = CHILD(tree, 0); 2234 tree = CHILD(tree, 0);
2134 switch (TYPE(tree)) { 2235 switch (TYPE(tree)) {
2135 case LESS: 2236 case LESS:
2136 case GREATER: 2237 case GREATER:
2137 case EQEQUAL: 2238 case EQEQUAL:
2138 case EQUAL: 2239 case EQUAL:
2139 case LESSEQUAL: 2240 case LESSEQUAL:
2140 case GREATEREQUAL: 2241 case GREATEREQUAL:
2141 case NOTEQUAL: 2242 case NOTEQUAL:
2142 res = 1; 2243 res = 1;
2143 break; 2244 break;
2144 case NAME: 2245 case NAME:
2145 res = ((strcmp(STR(tree), "in") == 0) 2246 res = ((strcmp(STR(tree), "in") == 0)
2146 || (strcmp(STR(tree), "is") == 0)); 2247 || (strcmp(STR(tree), "is") == 0));
2147 if (!res) { 2248 if (!res) {
2148 PyErr_Format(parser_error, 2249 PyErr_Format(parser_error,
2149 "illegal operator '%s'", STR(tree)); 2250 "illegal operator '%s'", STR(tree));
2150 } 2251 }
2151 break; 2252 break;
2152 default: 2253 default:
2153 err_string("illegal comparison operator type"); 2254 err_string("illegal comparison operator type");
2154 break; 2255 break;
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
2368 break; 2469 break;
2369 case LBRACE: 2470 case LBRACE:
2370 res = ((nch <= 3) 2471 res = ((nch <= 3)
2371 && validate_ntype(CHILD(tree, nch - 1), RBRACE)); 2472 && validate_ntype(CHILD(tree, nch - 1), RBRACE));
2372 2473
2373 if (res && (nch == 3)) 2474 if (res && (nch == 3))
2374 res = validate_dictorsetmaker(CHILD(tree, 1)); 2475 res = validate_dictorsetmaker(CHILD(tree, 1));
2375 break; 2476 break;
2376 case NAME: 2477 case NAME:
2377 case NUMBER: 2478 case NUMBER:
2479 case ELLIPSIS:
2378 res = (nch == 1); 2480 res = (nch == 1);
2379 break; 2481 break;
2380 case STRING: 2482 case STRING:
2381 for (pos = 1; res && (pos < nch); ++pos) 2483 for (pos = 1; res && (pos < nch); ++pos)
2382 res = validate_ntype(CHILD(tree, pos), STRING); 2484 res = validate_ntype(CHILD(tree, pos), STRING);
2383 break;
2384 case DOT:
2385 res = (nch == 3 &&
2386 validate_ntype(CHILD(tree, 1), DOT) &&
2387 validate_ntype(CHILD(tree, 2), DOT));
2388 break; 2485 break;
2389 default: 2486 default:
2390 res = 0; 2487 res = 0;
2391 break; 2488 break;
2392 } 2489 }
2393 } 2490 }
2394 return (res); 2491 return (res);
2395 } 2492 }
2396 2493
2397 2494
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
2502 int ok = (validate_ntype(tree, with_stmt) 2599 int ok = (validate_ntype(tree, with_stmt)
2503 && (nch % 2 == 0) 2600 && (nch % 2 == 0)
2504 && validate_name(CHILD(tree, 0), "with") 2601 && validate_name(CHILD(tree, 0), "with")
2505 && validate_colon(RCHILD(tree, -2)) 2602 && validate_colon(RCHILD(tree, -2))
2506 && validate_suite(RCHILD(tree, -1))); 2603 && validate_suite(RCHILD(tree, -1)));
2507 for (i = 1; ok && i < nch - 2; i += 2) 2604 for (i = 1; ok && i < nch - 2; i += 2)
2508 ok = validate_with_item(CHILD(tree, i)); 2605 ok = validate_with_item(CHILD(tree, i));
2509 return ok; 2606 return ok;
2510 } 2607 }
2511 2608
2512 /* funcdef: 2609 /* funcdef: 'def' NAME parameters ['->' test] ':' suite */
2513 * 2610
2514 * -5 -4 -3 -2 -1
2515 * 'def' NAME parameters ':' suite
2516 */
2517 static int 2611 static int
2518 validate_funcdef(node *tree) 2612 validate_funcdef(node *tree)
2519 { 2613 {
2520 int nch = NCH(tree); 2614 int nch = NCH(tree);
2521 int ok = (validate_ntype(tree, funcdef) 2615 int res = validate_ntype(tree, funcdef);
2522 && (nch == 5) 2616 if (res) {
2523 && validate_name(RCHILD(tree, -5), "def") 2617 if (nch == 5) {
2524 && validate_ntype(RCHILD(tree, -4), NAME) 2618 res = (validate_name(CHILD(tree, 0), "def")
2525 && validate_colon(RCHILD(tree, -2)) 2619 && validate_ntype(CHILD(tree, 1), NAME)
2526 && validate_parameters(RCHILD(tree, -3)) 2620 && validate_parameters(CHILD(tree, 2))
2527 && validate_suite(RCHILD(tree, -1))); 2621 && validate_colon(CHILD(tree, 3))
2528 return ok; 2622 && validate_suite(CHILD(tree, 4)));
2623 }
2624 else if (nch == 7) {
2625 res = (validate_name(CHILD(tree, 0), "def")
2626 && validate_ntype(CHILD(tree, 1), NAME)
2627 && validate_parameters(CHILD(tree, 2))
2628 && validate_rarrow(CHILD(tree, 3))
2629 && validate_test(CHILD(tree, 4))
2630 && validate_colon(CHILD(tree, 5))
2631 && validate_suite(CHILD(tree, 6)));
2632 }
2633 else {
2634 res = 0;
2635 err_string("illegal number of children for funcdef");
2636 }
2637 }
2638 return res;
2529 } 2639 }
2530 2640
2531 2641
2532 /* decorated 2642 /* decorated
2533 * decorators (classdef | funcdef) 2643 * decorators (classdef | funcdef)
2534 */ 2644 */
2535 static int 2645 static int
2536 validate_decorated(node *tree) 2646 validate_decorated(node *tree)
2537 { 2647 {
2538 int nch = NCH(tree); 2648 int nch = NCH(tree);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
2670 2780
2671 /* argument: 2781 /* argument:
2672 * 2782 *
2673 * [test '='] test [comp_for] 2783 * [test '='] test [comp_for]
2674 */ 2784 */
2675 static int 2785 static int
2676 validate_argument(node *tree) 2786 validate_argument(node *tree)
2677 { 2787 {
2678 int nch = NCH(tree); 2788 int nch = NCH(tree);
2679 int res = (validate_ntype(tree, argument) 2789 int res = (validate_ntype(tree, argument)
2680 && ((nch == 1) || (nch == 2) || (nch == 3)) 2790 && ((nch == 1) || (nch == 2) || (nch == 3)));
2681 && validate_test(CHILD(tree, 0))); 2791 if (res)
2682 2792 res = validate_test(CHILD(tree, 0));
2683 if (res && (nch == 2)) 2793 if (res && (nch == 2))
2684 res = validate_comp_for(CHILD(tree, 1)); 2794 res = validate_comp_for(CHILD(tree, 1));
2685 else if (res && (nch == 3)) 2795 else if (res && (nch == 3))
2686 res = (validate_equal(CHILD(tree, 1)) 2796 res = (validate_equal(CHILD(tree, 1))
2687 && validate_test(CHILD(tree, 2))); 2797 && validate_test(CHILD(tree, 2)));
2688 2798
2689 return (res); 2799 return (res);
2690 } 2800 }
2691 2801
2692 2802
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
2831 } 2941 }
2832 2942
2833 2943
2834 static int 2944 static int
2835 validate_exprlist(node *tree) 2945 validate_exprlist(node *tree)
2836 { 2946 {
2837 return (validate_repeating_list(tree, exprlist, 2947 return (validate_repeating_list(tree, exprlist,
2838 validate_expr_or_star_expr, "exprlist")); 2948 validate_expr_or_star_expr, "exprlist"));
2839 } 2949 }
2840 2950
2841 2951 /*
2952 * dictorsetmaker:
2953 *
2954 * (test ':' test (comp_for | (',' test ':' test)* [','])) |
2955 * (test (comp_for | (',' test)* [',']))
2956 */
2842 static int 2957 static int
2843 validate_dictorsetmaker(node *tree) 2958 validate_dictorsetmaker(node *tree)
2844 { 2959 {
2845 int nch = NCH(tree); 2960 int nch = NCH(tree);
2846 int res = (validate_ntype(tree, dictorsetmaker) 2961 int res;
2847 && (nch >= 3) 2962 int i = 0;
2848 && validate_test(CHILD(tree, 0)) 2963
2849 && validate_colon(CHILD(tree, 1)) 2964 res = validate_ntype(tree, dictorsetmaker);
2850 && validate_test(CHILD(tree, 2))); 2965 if (!res)
2851 2966 return 0;
2852 if (res && ((nch % 4) == 0)) 2967
2853 res = validate_comma(CHILD(tree, --nch)); 2968 if (nch - i < 1) {
2854 else if (res) 2969 (void) validate_numnodes(tree, 1, "dictorsetmaker");
2855 res = ((nch % 4) == 3); 2970 return 0;
2856 2971 }
2857 if (res && (nch > 3)) { 2972
2858 int pos = 3; 2973 res = validate_test(CHILD(tree, i++));
2859 /* ( ',' test ':' test )* */ 2974 if (!res)
2860 while (res && (pos < nch)) { 2975 return 0;
2861 res = (validate_comma(CHILD(tree, pos)) 2976
2862 && validate_test(CHILD(tree, pos + 1)) 2977 if (nch - i >= 2 && TYPE(CHILD(tree, i)) == COLON) {
2863 && validate_colon(CHILD(tree, pos + 2)) 2978 /* Dictionary display or dictionary comprehension. */
2864 && validate_test(CHILD(tree, pos + 3))); 2979 res = (validate_colon(CHILD(tree, i++))
2865 pos += 4; 2980 && validate_test(CHILD(tree, i++)));
2866 } 2981 if (!res)
2867 } 2982 return 0;
2868 return (res); 2983
2984 if (nch - i >= 1 && TYPE(CHILD(tree, i)) == comp_for) {
2985 /* Dictionary comprehension. */
2986 res = validate_comp_for(CHILD(tree, i++));
2987 if (!res)
2988 return 0;
2989 }
2990 else {
2991 /* Dictionary display. */
2992 while (nch - i >= 4) {
2993 res = (validate_comma(CHILD(tree, i++))
2994 && validate_test(CHILD(tree, i++))
2995 && validate_colon(CHILD(tree, i++))
2996 && validate_test(CHILD(tree, i++)));
2997 if (!res)
2998 return 0;
2999 }
3000 if (nch - i == 1) {
3001 res = validate_comma(CHILD(tree, i++));
3002 if (!res)
3003 return 0;
3004 }
3005 }
3006 }
3007 else {
3008 /* Set display or set comprehension. */
3009 if (nch - i >= 1 && TYPE(CHILD(tree, i)) == comp_for) {
3010 /* Set comprehension. */
3011 res = validate_comp_for(CHILD(tree, i++));
3012 if (!res)
3013 return 0;
3014 }
3015 else {
3016 /* Set display. */
3017 while (nch - i >= 2) {
3018 res = (validate_comma(CHILD(tree, i++))
3019 && validate_test(CHILD(tree, i++)));
3020 if (!res)
3021 return 0;
3022 }
3023 if (nch - i == 1) {
3024 res = validate_comma(CHILD(tree, i++));
3025 if (!res)
3026 return 0;
3027 }
3028 }
3029 }
3030
3031 if (nch - i > 0) {
3032 err_string("Illegal trailing nodes for dictorsetmaker.");
3033 return 0;
3034 }
3035
3036 return 1;
2869 } 3037 }
2870 3038
2871 3039
2872 static int 3040 static int
2873 validate_eval_input(node *tree) 3041 validate_eval_input(node *tree)
2874 { 3042 {
2875 int pos; 3043 int pos;
2876 int nch = NCH(tree); 3044 int nch = NCH(tree);
2877 int res = (validate_ntype(tree, eval_input) 3045 int res = (validate_ntype(tree, eval_input)
2878 && (nch >= 2) 3046 && (nch >= 2)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2914 break; 3082 break;
2915 /* 3083 /*
2916 * "Trivial" parse tree nodes. 3084 * "Trivial" parse tree nodes.
2917 * (Why did I call these trivial?) 3085 * (Why did I call these trivial?)
2918 */ 3086 */
2919 case stmt: 3087 case stmt:
2920 res = validate_stmt(tree); 3088 res = validate_stmt(tree);
2921 break; 3089 break;
2922 case small_stmt: 3090 case small_stmt:
2923 /* 3091 /*
2924 * expr_stmt | del_stmt | pass_stmt | flow_stmt 3092 * expr_stmt | del_stmt | pass_stmt | flow_stmt |
2925 * | import_stmt | global_stmt | assert_stmt 3093 * import_stmt | global_stmt | nonlocal_stmt | assert_stmt
2926 */ 3094 */
2927 res = validate_small_stmt(tree); 3095 res = validate_small_stmt(tree);
2928 break; 3096 break;
2929 case flow_stmt: 3097 case flow_stmt:
2930 res = (validate_numnodes(tree, 1, "flow_stmt") 3098 res = (validate_numnodes(tree, 1, "flow_stmt")
2931 && ((TYPE(CHILD(tree, 0)) == break_stmt) 3099 && ((TYPE(CHILD(tree, 0)) == break_stmt)
2932 || (TYPE(CHILD(tree, 0)) == continue_stmt) 3100 || (TYPE(CHILD(tree, 0)) == continue_stmt)
2933 || (TYPE(CHILD(tree, 0)) == yield_stmt) 3101 || (TYPE(CHILD(tree, 0)) == yield_stmt)
2934 || (TYPE(CHILD(tree, 0)) == return_stmt) 3102 || (TYPE(CHILD(tree, 0)) == return_stmt)
2935 || (TYPE(CHILD(tree, 0)) == raise_stmt))); 3103 || (TYPE(CHILD(tree, 0)) == raise_stmt)));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2981 res = validate_import_stmt(tree); 3149 res = validate_import_stmt(tree);
2982 break; 3150 break;
2983 case import_name: 3151 case import_name:
2984 res = validate_import_name(tree); 3152 res = validate_import_name(tree);
2985 break; 3153 break;
2986 case import_from: 3154 case import_from:
2987 res = validate_import_from(tree); 3155 res = validate_import_from(tree);
2988 break; 3156 break;
2989 case global_stmt: 3157 case global_stmt:
2990 res = validate_global_stmt(tree); 3158 res = validate_global_stmt(tree);
3159 break;
3160 case nonlocal_stmt:
3161 res = validate_nonlocal_stmt(tree);
2991 break; 3162 break;
2992 case assert_stmt: 3163 case assert_stmt:
2993 res = validate_assert_stmt(tree); 3164 res = validate_assert_stmt(tree);
2994 break; 3165 break;
2995 case if_stmt: 3166 case if_stmt:
2996 res = validate_if(tree); 3167 res = validate_if(tree);
2997 break; 3168 break;
2998 case while_stmt: 3169 case while_stmt:
2999 res = validate_while(tree); 3170 res = validate_while(tree);
3000 break; 3171 break;
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
3246 PyModule_AddStringConstant(module, "__version__", 3417 PyModule_AddStringConstant(module, "__version__",
3247 parser_version_string); 3418 parser_version_string);
3248 3419
3249 /* Register to support pickling. 3420 /* Register to support pickling.
3250 * If this fails, the import of this module will fail because an 3421 * If this fails, the import of this module will fail because an
3251 * exception will be raised here; should we clear the exception? 3422 * exception will be raised here; should we clear the exception?
3252 */ 3423 */
3253 copyreg = PyImport_ImportModuleNoBlock("copyreg"); 3424 copyreg = PyImport_ImportModuleNoBlock("copyreg");
3254 if (copyreg != NULL) { 3425 if (copyreg != NULL) {
3255 PyObject *func, *pickler; 3426 PyObject *func, *pickler;
3256 3427 _Py_IDENTIFIER(pickle);
3257 func = PyObject_GetAttrString(copyreg, "pickle"); 3428 _Py_IDENTIFIER(sequence2st);
3258 pickle_constructor = PyObject_GetAttrString(module, "sequence2st"); 3429 _Py_IDENTIFIER(_pickler);
3259 pickler = PyObject_GetAttrString(module, "_pickler"); 3430
3431 func = _PyObject_GetAttrId(copyreg, &PyId_pickle);
3432 pickle_constructor = _PyObject_GetAttrId(module, &PyId_sequence2st);
3433 pickler = _PyObject_GetAttrId(module, &PyId__pickler);
3260 Py_XINCREF(pickle_constructor); 3434 Py_XINCREF(pickle_constructor);
3261 if ((func != NULL) && (pickle_constructor != NULL) 3435 if ((func != NULL) && (pickle_constructor != NULL)
3262 && (pickler != NULL)) { 3436 && (pickler != NULL)) {
3263 PyObject *res; 3437 PyObject *res;
3264 3438
3265 res = PyObject_CallFunctionObjArgs(func, &PyST_Type, pickler, 3439 res = PyObject_CallFunctionObjArgs(func, &PyST_Type, pickler,
3266 pickle_constructor, NULL); 3440 pickle_constructor, NULL);
3267 Py_XDECREF(res); 3441 Py_XDECREF(res);
3268 } 3442 }
3269 Py_XDECREF(func); 3443 Py_XDECREF(func);
3270 Py_XDECREF(pickle_constructor); 3444 Py_XDECREF(pickle_constructor);
3271 Py_XDECREF(pickler); 3445 Py_XDECREF(pickler);
3272 Py_DECREF(copyreg); 3446 Py_DECREF(copyreg);
3273 } 3447 }
3274 return module; 3448 return module;
3275 } 3449 }
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+