Mercurial > cpython-lru_cache-weakref
comparison Python/Python-ast.c @ 71454:3301689bd78d 3.2
type check AST strings and identifiers
This is related to a21829180423 as well as #12609 and #12610.
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Fri, 22 Jul 2011 10:50:23 -0500 |
| parents | 3c9232a684ae |
| children | 08932ec9ddb1 75d56cf3020c |
comparison
equal
deleted
inserted
replaced
| 71448:f0475f78d45c | 71454:3301689bd78d |
|---|---|
| 1 /* File automatically generated by Parser/asdl_c.py. */ | 1 /* File automatically generated by Parser/asdl_c.py. */ |
| 2 | 2 |
| 3 | 3 |
| 4 /* | 4 /* |
| 5 __version__ 82163. | 5 __version__ . |
| 6 | 6 |
| 7 This module must be committed separately after each AST grammar change; | 7 This module must be committed separately after each AST grammar change; |
| 8 The __version__ number is set to the revision number of the commit | 8 The __version__ number is set to the revision number of the commit |
| 9 containing the grammar change. | 9 containing the grammar change. |
| 10 */ | 10 */ |
| 598 Py_XINCREF(obj); | 598 Py_XINCREF(obj); |
| 599 *out = obj; | 599 *out = obj; |
| 600 return 0; | 600 return 0; |
| 601 } | 601 } |
| 602 | 602 |
| 603 #define obj2ast_identifier obj2ast_object | 603 static int obj2ast_stringlike(PyObject* obj, PyObject** out, PyArena* arena, |
| 604 #define obj2ast_string obj2ast_object | 604 const char *name) |
| 605 { | |
| 606 if (!PyUnicode_CheckExact(name)) { | |
| 607 PyErr_Format(PyExc_TypeError, "AST %s must be of type str", name); | |
| 608 return 1; | |
| 609 } | |
| 610 return obj2ast_object(obj, out, arena); | |
| 611 } | |
| 612 | |
| 613 static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) | |
| 614 { | |
| 615 return obj2ast_stringlike(obj, out, arena, "identifier"); | |
| 616 } | |
| 617 | |
| 618 static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) | |
| 619 { | |
| 620 return obj2ast_stringlike(obj, out, arena, "string"); | |
| 621 } | |
| 605 | 622 |
| 606 static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) | 623 static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
| 607 { | 624 { |
| 608 int i; | 625 int i; |
| 609 if (!PyLong_Check(obj)) { | 626 if (!PyLong_Check(obj)) { |
| 6737 d = PyModule_GetDict(m); | 6754 d = PyModule_GetDict(m); |
| 6738 if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return | 6755 if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return |
| 6739 NULL; | 6756 NULL; |
| 6740 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) | 6757 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) |
| 6741 return NULL; | 6758 return NULL; |
| 6742 if (PyModule_AddStringConstant(m, "__version__", "82163") < 0) | 6759 if (PyModule_AddStringConstant(m, "__version__", "") < 0) |
| 6743 return NULL; | 6760 return NULL; |
| 6744 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return | 6761 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return |
| 6745 NULL; | 6762 NULL; |
| 6746 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) | 6763 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) |
| 6747 return NULL; | 6764 return NULL; |
