comparison Python/Python-ast.c @ 71452:a21829180423 2.7

verify the types of AST strings and identifiers (closes #12609 and #12610)
author Benjamin Peterson <benjamin@python.org>
date Fri, 22 Jul 2011 10:39:50 -0500
parents 9d004a9a2ced
children 7a72068d88fe
comparison
equal deleted inserted replaced
71451:daca32a1431f 71452:a21829180423
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__ 82160. 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 */
592 Py_XINCREF(obj); 592 Py_XINCREF(obj);
593 *out = obj; 593 *out = obj;
594 return 0; 594 return 0;
595 } 595 }
596 596
597 #define obj2ast_identifier obj2ast_object 597 static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
598 #define obj2ast_string obj2ast_object 598 {
599 if (!PyString_CheckExact(obj)) {
600 PyErr_Format(PyExc_TypeError,
601 "AST identifier must be of type str");
602 return 1;
603 }
604 return obj2ast_object(obj, out, arena);
605 }
606
607 static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
608 {
609 if (!PyString_CheckExact(obj) && !PyUnicode_CheckExact(obj)) {
610 PyErr_SetString(PyExc_TypeError,
611 "AST string must be of type str or unicode");
612 return 1;
613 }
614 return obj2ast_object(obj, out, arena);
615 }
599 616
600 static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) 617 static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
601 { 618 {
602 int i; 619 int i;
603 if (!PyInt_Check(obj) && !PyLong_Check(obj)) { 620 if (!PyInt_Check(obj) && !PyLong_Check(obj)) {
6568 if (!m) return; 6585 if (!m) return;
6569 d = PyModule_GetDict(m); 6586 d = PyModule_GetDict(m);
6570 if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return; 6587 if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return;
6571 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) 6588 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
6572 return; 6589 return;
6573 if (PyModule_AddStringConstant(m, "__version__", "82160") < 0) 6590 if (PyModule_AddStringConstant(m, "__version__", "") < 0)
6574 return; 6591 return;
6575 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return; 6592 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
6576 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) 6593 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
6577 return; 6594 return;
6578 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) 6595 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)