|
19 | 19 | #include "opcode.h" |
20 | 20 | #include "structmember.h" |
21 | 21 |
|
22 | | -#define REPR(O) PyString_AS_STRING(PyObject_Repr(O)) |
23 | | - |
24 | 22 | #include <ctype.h> |
25 | 23 |
|
26 | 24 | /* Three symbols from graminit.h are also defined in Python.h, with |
@@ -66,9 +64,6 @@ int Py_OptimizeFlag = 0; |
66 | 64 | #define ILLEGAL_IMPORT_STAR \ |
67 | 65 | "'from ... import *' may only occur in a module scope" |
68 | 66 |
|
69 | | -#define ILLEGAL_IMPORT_GLOBAL \ |
70 | | -"may not import name '%.400s' because it is declared global" |
71 | | - |
72 | 67 | #define MANGLE_LEN 256 |
73 | 68 |
|
74 | 69 | #define OFF(x) offsetof(PyCodeObject, x) |
@@ -2204,7 +2199,7 @@ com_make_closure(struct compiling *c, PyCodeObject *co) |
2204 | 2199 | arg = com_lookup_arg(c->c_freevars, name); |
2205 | 2200 | if (arg == -1) { |
2206 | 2201 | fprintf(stderr, "lookup %s in %s %d %d\n", |
2207 | | - REPR(name), c->c_name, reftype, arg); |
| 2202 | + PyObject_REPR(name), c->c_name, reftype, arg); |
2208 | 2203 | Py_FatalError("com_make_closure()"); |
2209 | 2204 | } |
2210 | 2205 | com_addoparg(c, LOAD_CLOSURE, arg); |
@@ -3995,7 +3990,8 @@ get_ref_type(struct compiling *c, char *name) |
3995 | 3990 | { |
3996 | 3991 | char buf[250]; |
3997 | 3992 | sprintf(buf, "unknown scope for %.100s in %.100s (%s)", |
3998 | | - name, c->c_name, REPR(c->c_symtable->st_cur_id)); |
| 3993 | + name, c->c_name, |
| 3994 | + PyObject_REPR(c->c_symtable->st_cur_id)); |
3999 | 3995 | Py_FatalError(buf); |
4000 | 3996 | } |
4001 | 3997 | return -1; /* can't get here */ |
@@ -4117,13 +4113,6 @@ symtable_load_symbols(struct compiling *c) |
4117 | 4113 | com_error(c, PyExc_SyntaxError, buf); |
4118 | 4114 | goto fail; |
4119 | 4115 | } |
4120 | | - if (info & DEF_IMPORT) { |
4121 | | - char buf[500]; |
4122 | | - sprintf(buf, ILLEGAL_IMPORT_GLOBAL, |
4123 | | - PyString_AS_STRING(name)); |
4124 | | - com_error(c, PyExc_SyntaxError, buf); |
4125 | | - goto fail; |
4126 | | - } |
4127 | 4116 | if (PyDict_SetItem(c->c_globals, name, Py_None) < 0) |
4128 | 4117 | goto fail; |
4129 | 4118 | } else if (info & DEF_FREE_GLOBAL) { |
@@ -4529,7 +4518,7 @@ symtable_add_def_o(struct symtable *st, PyObject *dict, |
4529 | 4518 | val = PyInt_AS_LONG(o); |
4530 | 4519 | if ((flag & DEF_PARAM) && (val & DEF_PARAM)) { |
4531 | 4520 | PyErr_Format(PyExc_SyntaxError, DUPLICATE_ARGUMENT, |
4532 | | - name); |
| 4521 | + PyString_AsString(name)); |
4533 | 4522 | return -1; |
4534 | 4523 | } |
4535 | 4524 | val |= flag; |
@@ -4626,15 +4615,24 @@ symtable_node(struct symtable *st, node *n) |
4626 | 4615 | case import_stmt: |
4627 | 4616 | symtable_import(st, n); |
4628 | 4617 | break; |
4629 | | - case exec_stmt: |
4630 | | - if (PyDict_SetItemString(st->st_cur, NOOPT, Py_None) < 0) |
| 4618 | + case exec_stmt: { |
| 4619 | + PyObject *zero = PyInt_FromLong(0); |
| 4620 | + if (zero == NULL) |
4631 | 4621 | st->st_errors++; |
| 4622 | + else { |
| 4623 | + if (PyDict_SetItemString(st->st_cur, NOOPT, |
| 4624 | + zero) < 0) |
| 4625 | + st->st_errors++; |
| 4626 | + Py_DECREF(zero); |
| 4627 | + } |
4632 | 4628 | symtable_node(st, CHILD(n, 1)); |
4633 | 4629 | if (NCH(n) > 2) |
4634 | 4630 | symtable_node(st, CHILD(n, 3)); |
4635 | 4631 | if (NCH(n) > 4) |
4636 | 4632 | symtable_node(st, CHILD(n, 5)); |
4637 | 4633 | break; |
| 4634 | + |
| 4635 | + } |
4638 | 4636 | case except_clause: |
4639 | 4637 | if (NCH(n) == 4) |
4640 | 4638 | symtable_assign(st, CHILD(n, 3), 0); |
@@ -4848,24 +4846,29 @@ static void |
4848 | 4846 | symtable_import(struct symtable *st, node *n) |
4849 | 4847 | { |
4850 | 4848 | int i; |
4851 | | - /* |
4852 | | - import_stmt: 'import' dotted_as_name (',' dotted_as_name)* |
| 4849 | + /* import_stmt: 'import' dotted_as_name (',' dotted_as_name)* |
4853 | 4850 | | 'from' dotted_name 'import' |
4854 | 4851 | ('*' | import_as_name (',' import_as_name)*) |
4855 | | - import_as_name: NAME [NAME NAME] |
| 4852 | + import_as_name: NAME [NAME NAME] |
4856 | 4853 | */ |
4857 | 4854 |
|
4858 | 4855 | if (STR(CHILD(n, 0))[0] == 'f') { /* from */ |
4859 | 4856 | if (TYPE(CHILD(n, 3)) == STAR) { |
| 4857 | + PyObject *zero = PyInt_FromLong(0); |
4860 | 4858 | if (st->st_cur_type != TYPE_MODULE) { |
4861 | 4859 | PyErr_SetString(PyExc_SyntaxError, |
4862 | 4860 | ILLEGAL_IMPORT_STAR); |
4863 | 4861 | st->st_errors++; |
4864 | 4862 | return; |
4865 | 4863 | } |
4866 | | - if (PyDict_SetItemString(st->st_cur, NOOPT, |
4867 | | - Py_None) < 0) |
| 4864 | + if (zero == NULL) |
4868 | 4865 | st->st_errors++; |
| 4866 | + else { |
| 4867 | + if (PyDict_SetItemString(st->st_cur, NOOPT, |
| 4868 | + zero) < 0) |
| 4869 | + st->st_errors++; |
| 4870 | + Py_DECREF(zero); |
| 4871 | + } |
4869 | 4872 | } else { |
4870 | 4873 | for (i = 3; i < NCH(n); i += 2) { |
4871 | 4874 | node *c = CHILD(n, i); |
|
0 commit comments