comparison Python/Python-ast.c @ 66253:e37344a8f0c9

use %R format code; fixes invalid dereferencing #10391
author Benjamin Peterson <benjamin@python.org>
date Sat, 20 Nov 2010 01:38:49 +0000
parents 504c499e8c95
children b9be45f433b9
comparison
equal deleted inserted replaced
66252:d9c89072044e 66253:e37344a8f0c9
3373 3373
3374 int 3374 int
3375 obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) 3375 obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
3376 { 3376 {
3377 PyObject* tmp = NULL; 3377 PyObject* tmp = NULL;
3378 tmp = tmp;
3378 int isinstance; 3379 int isinstance;
3379 3380
3380 3381
3381 if (obj == Py_None) { 3382 if (obj == Py_None) {
3382 *out = NULL; 3383 *out = NULL;
3512 *out = Suite(body, arena); 3513 *out = Suite(body, arena);
3513 if (*out == NULL) goto failed; 3514 if (*out == NULL) goto failed;
3514 return 0; 3515 return 0;
3515 } 3516 }
3516 3517
3517 tmp = PyObject_Repr(obj); 3518 PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
3518 if (tmp == NULL) goto failed; 3519 failed:
3519 PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %.400s", PyBytes_AS_STRING(tmp));
3520 failed:
3521 Py_XDECREF(tmp);
3522 return 1; 3520 return 1;
3523 } 3521 }
3524 3522
3525 int 3523 int
3526 obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) 3524 obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
3527 { 3525 {
3528 PyObject* tmp = NULL; 3526 PyObject* tmp = NULL;
3527 tmp = tmp;
3529 int isinstance; 3528 int isinstance;
3530 3529
3531 int lineno; 3530 int lineno;
3532 int col_offset; 3531 int col_offset;
3533 3532
4710 *out = Continue(lineno, col_offset, arena); 4709 *out = Continue(lineno, col_offset, arena);
4711 if (*out == NULL) goto failed; 4710 if (*out == NULL) goto failed;
4712 return 0; 4711 return 0;
4713 } 4712 }
4714 4713
4715 tmp = PyObject_Repr(obj); 4714 PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
4716 if (tmp == NULL) goto failed; 4715 failed:
4717 PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %.400s", PyBytes_AS_STRING(tmp));
4718 failed:
4719 Py_XDECREF(tmp);
4720 return 1; 4716 return 1;
4721 } 4717 }
4722 4718
4723 int 4719 int
4724 obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) 4720 obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
4725 { 4721 {
4726 PyObject* tmp = NULL; 4722 PyObject* tmp = NULL;
4723 tmp = tmp;
4727 int isinstance; 4724 int isinstance;
4728 4725
4729 int lineno; 4726 int lineno;
4730 int col_offset; 4727 int col_offset;
4731 4728
5828 *out = Tuple(elts, ctx, lineno, col_offset, arena); 5825 *out = Tuple(elts, ctx, lineno, col_offset, arena);
5829 if (*out == NULL) goto failed; 5826 if (*out == NULL) goto failed;
5830 return 0; 5827 return 0;
5831 } 5828 }
5832 5829
5833 tmp = PyObject_Repr(obj); 5830 PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
5834 if (tmp == NULL) goto failed; 5831 failed:
5835 PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %.400s", PyBytes_AS_STRING(tmp));
5836 failed:
5837 Py_XDECREF(tmp);
5838 return 1; 5832 return 1;
5839 } 5833 }
5840 5834
5841 int 5835 int
5842 obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) 5836 obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)
5843 { 5837 {
5844 PyObject* tmp = NULL; 5838 PyObject* tmp = NULL;
5839 tmp = tmp;
5845 int isinstance; 5840 int isinstance;
5846 5841
5847 isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); 5842 isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type);
5848 if (isinstance == -1) { 5843 if (isinstance == -1) {
5849 return 1; 5844 return 1;
5891 if (isinstance) { 5886 if (isinstance) {
5892 *out = Param; 5887 *out = Param;
5893 return 0; 5888 return 0;
5894 } 5889 }
5895 5890
5896 tmp = PyObject_Repr(obj); 5891 PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
5897 if (tmp == NULL) goto failed;
5898 PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %.400s", PyBytes_AS_STRING(tmp));
5899 failed:
5900 Py_XDECREF(tmp);
5901 return 1; 5892 return 1;
5902 } 5893 }
5903 5894
5904 int 5895 int
5905 obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) 5896 obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
5906 { 5897 {
5907 PyObject* tmp = NULL; 5898 PyObject* tmp = NULL;
5899 tmp = tmp;
5908 int isinstance; 5900 int isinstance;
5909 5901
5910 5902
5911 if (obj == Py_None) { 5903 if (obj == Py_None) {
5912 *out = NULL; 5904 *out = NULL;
6016 *out = Index(value, arena); 6008 *out = Index(value, arena);
6017 if (*out == NULL) goto failed; 6009 if (*out == NULL) goto failed;
6018 return 0; 6010 return 0;
6019 } 6011 }
6020 6012
6021 tmp = PyObject_Repr(obj); 6013 PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj);
6022 if (tmp == NULL) goto failed; 6014 failed:
6023 PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %.400s", PyBytes_AS_STRING(tmp));
6024 failed:
6025 Py_XDECREF(tmp);
6026 return 1; 6015 return 1;
6027 } 6016 }
6028 6017
6029 int 6018 int
6030 obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) 6019 obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)
6031 { 6020 {
6032 PyObject* tmp = NULL; 6021 PyObject* tmp = NULL;
6022 tmp = tmp;
6033 int isinstance; 6023 int isinstance;
6034 6024
6035 isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); 6025 isinstance = PyObject_IsInstance(obj, (PyObject *)And_type);
6036 if (isinstance == -1) { 6026 if (isinstance == -1) {
6037 return 1; 6027 return 1;
6047 if (isinstance) { 6037 if (isinstance) {
6048 *out = Or; 6038 *out = Or;
6049 return 0; 6039 return 0;
6050 } 6040 }
6051 6041
6052 tmp = PyObject_Repr(obj); 6042 PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
6053 if (tmp == NULL) goto failed;
6054 PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %.400s", PyBytes_AS_STRING(tmp));
6055 failed:
6056 Py_XDECREF(tmp);
6057 return 1; 6043 return 1;
6058 } 6044 }
6059 6045
6060 int 6046 int
6061 obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) 6047 obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)
6062 { 6048 {
6063 PyObject* tmp = NULL; 6049 PyObject* tmp = NULL;
6050 tmp = tmp;
6064 int isinstance; 6051 int isinstance;
6065 6052
6066 isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); 6053 isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type);
6067 if (isinstance == -1) { 6054 if (isinstance == -1) {
6068 return 1; 6055 return 1;
6158 if (isinstance) { 6145 if (isinstance) {
6159 *out = FloorDiv; 6146 *out = FloorDiv;
6160 return 0; 6147 return 0;
6161 } 6148 }
6162 6149
6163 tmp = PyObject_Repr(obj); 6150 PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
6164 if (tmp == NULL) goto failed;
6165 PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %.400s", PyBytes_AS_STRING(tmp));
6166 failed:
6167 Py_XDECREF(tmp);
6168 return 1; 6151 return 1;
6169 } 6152 }
6170 6153
6171 int 6154 int
6172 obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) 6155 obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)
6173 { 6156 {
6174 PyObject* tmp = NULL; 6157 PyObject* tmp = NULL;
6158 tmp = tmp;
6175 int isinstance; 6159 int isinstance;
6176 6160
6177 isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); 6161 isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type);
6178 if (isinstance == -1) { 6162 if (isinstance == -1) {
6179 return 1; 6163 return 1;
6205 if (isinstance) { 6189 if (isinstance) {
6206 *out = USub; 6190 *out = USub;
6207 return 0; 6191 return 0;
6208 } 6192 }
6209 6193
6210 tmp = PyObject_Repr(obj); 6194 PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
6211 if (tmp == NULL) goto failed;
6212 PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %.400s", PyBytes_AS_STRING(tmp));
6213 failed:
6214 Py_XDECREF(tmp);
6215 return 1; 6195 return 1;
6216 } 6196 }
6217 6197
6218 int 6198 int
6219 obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) 6199 obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)
6220 { 6200 {
6221 PyObject* tmp = NULL; 6201 PyObject* tmp = NULL;
6202 tmp = tmp;
6222 int isinstance; 6203 int isinstance;
6223 6204
6224 isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); 6205 isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type);
6225 if (isinstance == -1) { 6206 if (isinstance == -1) {
6226 return 1; 6207 return 1;
6300 if (isinstance) { 6281 if (isinstance) {
6301 *out = NotIn; 6282 *out = NotIn;
6302 return 0; 6283 return 0;
6303 } 6284 }
6304 6285
6305 tmp = PyObject_Repr(obj); 6286 PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
6306 if (tmp == NULL) goto failed;
6307 PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %.400s", PyBytes_AS_STRING(tmp));
6308 failed:
6309 Py_XDECREF(tmp);
6310 return 1; 6287 return 1;
6311 } 6288 }
6312 6289
6313 int 6290 int
6314 obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) 6291 obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)
6376 6353
6377 int 6354 int
6378 obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) 6355 obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
6379 { 6356 {
6380 PyObject* tmp = NULL; 6357 PyObject* tmp = NULL;
6358 tmp = tmp;
6381 int isinstance; 6359 int isinstance;
6382 6360
6383 int lineno; 6361 int lineno;
6384 int col_offset; 6362 int col_offset;
6385 6363
6471 arena); 6449 arena);
6472 if (*out == NULL) goto failed; 6450 if (*out == NULL) goto failed;
6473 return 0; 6451 return 0;
6474 } 6452 }
6475 6453
6476 tmp = PyObject_Repr(obj); 6454 PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
6477 if (tmp == NULL) goto failed; 6455 failed:
6478 PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %.400s", PyBytes_AS_STRING(tmp));
6479 failed:
6480 Py_XDECREF(tmp);
6481 return 1; 6456 return 1;
6482 } 6457 }
6483 6458
6484 int 6459 int
6485 obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) 6460 obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)