Mercurial > vim
comparison src/if_python3.c @ 4488:89ea7593fc0c v7.3.992
updated for version 7.3.992
Problem: Python: Too many type casts.
Solution: Change argument types. (ZyX)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Tue, 21 May 2013 18:30:34 +0200 |
parents | 8fe768bc1234 |
children | dff1542e64f9 |
comparison
equal
deleted
inserted
replaced
4487:0e0af28dde2f | 4488:89ea7593fc0c |
---|---|
65 #undef HAVE_FCNTL_H /* Clash with os_win32.h */ | 65 #undef HAVE_FCNTL_H /* Clash with os_win32.h */ |
66 | 66 |
67 #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02050000 | 67 #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02050000 |
68 # define PY_SSIZE_T_CLEAN | 68 # define PY_SSIZE_T_CLEAN |
69 #endif | 69 #endif |
70 | |
71 static void init_structs(void); | |
72 | 70 |
73 /* The "surrogateescape" error handler is new in Python 3.1 */ | 71 /* The "surrogateescape" error handler is new in Python 3.1 */ |
74 #if PY_VERSION_HEX >= 0x030100f0 | 72 #if PY_VERSION_HEX >= 0x030100f0 |
75 # define CODEC_ERROR_HANDLER "surrogateescape" | 73 # define CODEC_ERROR_HANDLER "surrogateescape" |
76 #else | 74 #else |
608 Py_XINCREF(p3imp_PyExc_RuntimeError); | 606 Py_XINCREF(p3imp_PyExc_RuntimeError); |
609 Py_XDECREF(exmod); | 607 Py_XDECREF(exmod); |
610 } | 608 } |
611 #endif /* DYNAMIC_PYTHON3 */ | 609 #endif /* DYNAMIC_PYTHON3 */ |
612 | 610 |
613 static PyObject *BufferDir(PyObject *, PyObject *); | |
614 | |
615 static int py3initialised = 0; | 611 static int py3initialised = 0; |
616 | 612 |
617 #define PYINITIALISED py3initialised | 613 #define PYINITIALISED py3initialised |
618 | 614 |
619 #define DICTKEY_DECL PyObject *bytes = NULL; | 615 #define DICTKEY_DECL PyObject *bytes = NULL; |
668 call_PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems) | 664 call_PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems) |
669 { | 665 { |
670 return PyType_GenericAlloc(type,nitems); | 666 return PyType_GenericAlloc(type,nitems); |
671 } | 667 } |
672 | 668 |
669 static PyObject *BufferDir(PyObject *); | |
673 static PyObject *OutputGetattro(PyObject *, PyObject *); | 670 static PyObject *OutputGetattro(PyObject *, PyObject *); |
674 static int OutputSetattro(PyObject *, PyObject *, PyObject *); | 671 static int OutputSetattro(PyObject *, PyObject *, PyObject *); |
675 static PyObject *BufferGetattro(PyObject *, PyObject *); | 672 static PyObject *BufferGetattro(PyObject *, PyObject *); |
676 static PyObject *TabPageGetattro(PyObject *, PyObject *); | 673 static PyObject *TabPageGetattro(PyObject *, PyObject *); |
677 static PyObject *WindowGetattro(PyObject *, PyObject *); | 674 static PyObject *WindowGetattro(PyObject *, PyObject *); |
1006 static int | 1003 static int |
1007 OutputSetattro(PyObject *self, PyObject *nameobj, PyObject *val) | 1004 OutputSetattro(PyObject *self, PyObject *nameobj, PyObject *val) |
1008 { | 1005 { |
1009 GET_ATTR_STRING(name, nameobj); | 1006 GET_ATTR_STRING(name, nameobj); |
1010 | 1007 |
1011 return OutputSetattr(self, name, val); | 1008 return OutputSetattr((OutputObject *)(self), name, val); |
1012 } | 1009 } |
1013 | 1010 |
1014 /***************/ | 1011 /***************/ |
1015 | 1012 |
1016 static int | 1013 static int |
1034 * -------------------------------------- | 1031 * -------------------------------------- |
1035 */ | 1032 */ |
1036 | 1033 |
1037 #define BufferType_Check(obj) ((obj)->ob_base.ob_type == &BufferType) | 1034 #define BufferType_Check(obj) ((obj)->ob_base.ob_type == &BufferType) |
1038 | 1035 |
1039 static Py_ssize_t BufferLength(PyObject *); | |
1040 static PyObject *BufferItem(PyObject *, Py_ssize_t); | |
1041 static PyObject* BufferSubscript(PyObject *self, PyObject *idx); | 1036 static PyObject* BufferSubscript(PyObject *self, PyObject *idx); |
1042 static Py_ssize_t BufferAsSubscript(PyObject *self, PyObject *idx, PyObject *val); | 1037 static Py_ssize_t BufferAsSubscript(PyObject *self, PyObject *idx, PyObject *val); |
1043 | |
1044 | 1038 |
1045 /* Line range type - Implementation functions | 1039 /* Line range type - Implementation functions |
1046 * -------------------------------------- | 1040 * -------------------------------------- |
1047 */ | 1041 */ |
1048 | 1042 |
1095 else | 1089 else |
1096 return PyObject_GenericGetAttr(self, nameobj); | 1090 return PyObject_GenericGetAttr(self, nameobj); |
1097 } | 1091 } |
1098 | 1092 |
1099 static PyObject * | 1093 static PyObject * |
1100 BufferDir(PyObject *self UNUSED, PyObject *args UNUSED) | 1094 BufferDir(PyObject *self UNUSED) |
1101 { | 1095 { |
1102 return Py_BuildValue("[sssss]", "name", "number", | 1096 return Py_BuildValue("[sssss]", "name", "number", |
1103 "append", "mark", "range"); | 1097 "append", "mark", "range"); |
1104 } | 1098 } |
1105 | 1099 |
1109 BufferSubscript(PyObject *self, PyObject* idx) | 1103 BufferSubscript(PyObject *self, PyObject* idx) |
1110 { | 1104 { |
1111 if (PyLong_Check(idx)) | 1105 if (PyLong_Check(idx)) |
1112 { | 1106 { |
1113 long _idx = PyLong_AsLong(idx); | 1107 long _idx = PyLong_AsLong(idx); |
1114 return BufferItem(self,_idx); | 1108 return BufferItem((BufferObject *)(self), _idx); |
1115 } else if (PySlice_Check(idx)) | 1109 } else if (PySlice_Check(idx)) |
1116 { | 1110 { |
1117 Py_ssize_t start, stop, step, slicelen; | 1111 Py_ssize_t start, stop, step, slicelen; |
1118 | 1112 |
1119 if (CheckBuffer((BufferObject *) self)) | 1113 if (CheckBuffer((BufferObject *) self)) |
1124 &start, &stop, | 1118 &start, &stop, |
1125 &step, &slicelen) < 0) | 1119 &step, &slicelen) < 0) |
1126 { | 1120 { |
1127 return NULL; | 1121 return NULL; |
1128 } | 1122 } |
1129 return BufferSlice(self, start, stop); | 1123 return BufferSlice((BufferObject *)(self), start, stop); |
1130 } | 1124 } |
1131 else | 1125 else |
1132 { | 1126 { |
1133 PyErr_SetString(PyExc_TypeError, _("index must be int or slice")); | 1127 PyErr_SetString(PyExc_TypeError, _("index must be int or slice")); |
1134 return NULL; | 1128 return NULL; |
1228 RangeSubscript(PyObject *self, PyObject* idx) | 1222 RangeSubscript(PyObject *self, PyObject* idx) |
1229 { | 1223 { |
1230 if (PyLong_Check(idx)) | 1224 if (PyLong_Check(idx)) |
1231 { | 1225 { |
1232 long _idx = PyLong_AsLong(idx); | 1226 long _idx = PyLong_AsLong(idx); |
1233 return RangeItem(self,_idx); | 1227 return RangeItem((RangeObject *)(self), _idx); |
1234 } else if (PySlice_Check(idx)) | 1228 } else if (PySlice_Check(idx)) |
1235 { | 1229 { |
1236 Py_ssize_t start, stop, step, slicelen; | 1230 Py_ssize_t start, stop, step, slicelen; |
1237 | 1231 |
1238 if (PySlice_GetIndicesEx((PyObject *)idx, | 1232 if (PySlice_GetIndicesEx((PyObject *)idx, |
1240 &start, &stop, | 1234 &start, &stop, |
1241 &step, &slicelen) < 0) | 1235 &step, &slicelen) < 0) |
1242 { | 1236 { |
1243 return NULL; | 1237 return NULL; |
1244 } | 1238 } |
1245 return RangeSlice(self, start, stop); | 1239 return RangeSlice((RangeObject *)(self), start, stop); |
1246 } | 1240 } |
1247 else | 1241 else |
1248 { | 1242 { |
1249 PyErr_SetString(PyExc_TypeError, _("index must be int or slice")); | 1243 PyErr_SetString(PyExc_TypeError, _("index must be int or slice")); |
1250 return NULL; | 1244 return NULL; |
1321 static int | 1315 static int |
1322 WindowSetattro(PyObject *self, PyObject *nameobj, PyObject *val) | 1316 WindowSetattro(PyObject *self, PyObject *nameobj, PyObject *val) |
1323 { | 1317 { |
1324 GET_ATTR_STRING(name, nameobj); | 1318 GET_ATTR_STRING(name, nameobj); |
1325 | 1319 |
1326 return WindowSetattr(self, name, val); | 1320 return WindowSetattr((WindowObject *)(self), name, val); |
1327 } | 1321 } |
1328 | 1322 |
1329 /* Tab page list object - Definitions | 1323 /* Tab page list object - Definitions |
1330 */ | 1324 */ |
1331 | 1325 |
1375 } | 1369 } |
1376 | 1370 |
1377 /* Dictionary object - Definitions | 1371 /* Dictionary object - Definitions |
1378 */ | 1372 */ |
1379 | 1373 |
1380 static PyInt DictionaryLength(PyObject *); | |
1381 | |
1382 static PyObject * | 1374 static PyObject * |
1383 DictionaryGetattro(PyObject *self, PyObject *nameobj) | 1375 DictionaryGetattro(PyObject *self, PyObject *nameobj) |
1384 { | 1376 { |
1385 DictionaryObject *this = ((DictionaryObject *) (self)); | 1377 DictionaryObject *this = ((DictionaryObject *) (self)); |
1386 | 1378 |
1396 | 1388 |
1397 static int | 1389 static int |
1398 DictionarySetattro(PyObject *self, PyObject *nameobj, PyObject *val) | 1390 DictionarySetattro(PyObject *self, PyObject *nameobj, PyObject *val) |
1399 { | 1391 { |
1400 GET_ATTR_STRING(name, nameobj); | 1392 GET_ATTR_STRING(name, nameobj); |
1401 return DictionarySetattr(self, name, val); | 1393 return DictionarySetattr((DictionaryObject *)(self), name, val); |
1402 } | 1394 } |
1403 | 1395 |
1404 /* List object - Definitions | 1396 /* List object - Definitions |
1405 */ | 1397 */ |
1406 | |
1407 static PyInt ListLength(PyObject *); | |
1408 static PyObject *ListItem(PyObject *, Py_ssize_t); | |
1409 | 1398 |
1410 static PySequenceMethods ListAsSeq = { | 1399 static PySequenceMethods ListAsSeq = { |
1411 (lenfunc) ListLength, /* sq_length, len(x) */ | 1400 (lenfunc) ListLength, /* sq_length, len(x) */ |
1412 (binaryfunc) 0, /* RangeConcat, sq_concat, x+y */ | 1401 (binaryfunc) 0, /* RangeConcat, sq_concat, x+y */ |
1413 (ssizeargfunc) 0, /* RangeRepeat, sq_repeat, x*n */ | 1402 (ssizeargfunc) 0, /* RangeRepeat, sq_repeat, x*n */ |
1428 /* mp_subscript */ (binaryfunc) ListSubscript, | 1417 /* mp_subscript */ (binaryfunc) ListSubscript, |
1429 /* mp_ass_subscript */ (objobjargproc) ListAsSubscript, | 1418 /* mp_ass_subscript */ (objobjargproc) ListAsSubscript, |
1430 }; | 1419 }; |
1431 | 1420 |
1432 static PyObject * | 1421 static PyObject * |
1433 ListSubscript(PyObject *self, PyObject* idxObject) | 1422 ListSubscript(PyObject *self, PyObject* idx) |
1434 { | 1423 { |
1435 if (PyLong_Check(idxObject)) | 1424 if (PyLong_Check(idx)) |
1436 { | 1425 { |
1437 long idx = PyLong_AsLong(idxObject); | 1426 long _idx = PyLong_AsLong(idx); |
1438 return ListItem(self, idx); | 1427 return ListItem((ListObject *)(self), _idx); |
1439 } | 1428 } |
1440 else if (PySlice_Check(idxObject)) | 1429 else if (PySlice_Check(idx)) |
1441 { | 1430 { |
1442 Py_ssize_t start, stop, step, slicelen; | 1431 Py_ssize_t start, stop, step, slicelen; |
1443 | 1432 |
1444 if (PySlice_GetIndicesEx(idxObject, ListLength(self), &start, &stop, | 1433 if (PySlice_GetIndicesEx(idx, ListLength((ListObject *)(self)), |
1445 &step, &slicelen) < 0) | 1434 &start, &stop, &step, &slicelen) < 0) |
1446 return NULL; | 1435 return NULL; |
1447 return ListSlice(self, start, stop); | 1436 return ListSlice((ListObject *)(self), start, stop); |
1448 } | 1437 } |
1449 else | 1438 else |
1450 { | 1439 { |
1451 PyErr_SetString(PyExc_TypeError, _("index must be int or slice")); | 1440 PyErr_SetString(PyExc_TypeError, _("index must be int or slice")); |
1452 return NULL; | 1441 return NULL; |
1453 } | 1442 } |
1454 } | 1443 } |
1455 | 1444 |
1456 static Py_ssize_t | 1445 static Py_ssize_t |
1457 ListAsSubscript(PyObject *self, PyObject *idxObject, PyObject *obj) | 1446 ListAsSubscript(PyObject *self, PyObject *idx, PyObject *obj) |
1458 { | 1447 { |
1459 if (PyLong_Check(idxObject)) | 1448 if (PyLong_Check(idx)) |
1460 { | 1449 { |
1461 long idx = PyLong_AsLong(idxObject); | 1450 long _idx = PyLong_AsLong(idx); |
1462 return ListAssItem(self, idx, obj); | 1451 return ListAssItem((ListObject *)(self), _idx, obj); |
1463 } | 1452 } |
1464 else if (PySlice_Check(idxObject)) | 1453 else if (PySlice_Check(idx)) |
1465 { | 1454 { |
1466 Py_ssize_t start, stop, step, slicelen; | 1455 Py_ssize_t start, stop, step, slicelen; |
1467 | 1456 |
1468 if (PySlice_GetIndicesEx(idxObject, ListLength(self), &start, &stop, | 1457 if (PySlice_GetIndicesEx(idx, ListLength((ListObject *)(self)), |
1469 &step, &slicelen) < 0) | 1458 &start, &stop, &step, &slicelen) < 0) |
1470 return -1; | 1459 return -1; |
1471 return ListAssSlice(self, start, stop, obj); | 1460 return ListAssSlice((ListObject *)(self), start, stop, obj); |
1472 } | 1461 } |
1473 else | 1462 else |
1474 { | 1463 { |
1475 PyErr_SetString(PyExc_TypeError, _("index must be int or slice")); | 1464 PyErr_SetString(PyExc_TypeError, _("index must be int or slice")); |
1476 return -1; | 1465 return -1; |
1490 | 1479 |
1491 static int | 1480 static int |
1492 ListSetattro(PyObject *self, PyObject *nameobj, PyObject *val) | 1481 ListSetattro(PyObject *self, PyObject *nameobj, PyObject *val) |
1493 { | 1482 { |
1494 GET_ATTR_STRING(name, nameobj); | 1483 GET_ATTR_STRING(name, nameobj); |
1495 return ListSetattr(self, name, val); | 1484 return ListSetattr((ListObject *)(self), name, val); |
1496 } | 1485 } |
1497 | 1486 |
1498 /* Function object - Definitions | 1487 /* Function object - Definitions |
1499 */ | 1488 */ |
1500 | 1489 |