| OLD | NEW |
| 1 | 1 |
| 2 /* Generic object operations; and implementation of None */ | 2 /* Generic object operations; and implementation of None */ |
| 3 | 3 |
| 4 #include "Python.h" | 4 #include "Python.h" |
| 5 #include "frameobject.h" | 5 #include "frameobject.h" |
| 6 | 6 |
| 7 #ifdef __cplusplus | 7 #ifdef __cplusplus |
| 8 extern "C" { | 8 extern "C" { |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1134 /* Test a value used as condition, e.g., in a for or if statement. | 1134 /* Test a value used as condition, e.g., in a for or if statement. |
| 1135 Return -1 if an error occurred */ | 1135 Return -1 if an error occurred */ |
| 1136 | 1136 |
| 1137 int | 1137 int |
| 1138 PyObject_IsTrue(PyObject *v) | 1138 PyObject_IsTrue(PyObject *v) |
| 1139 { | 1139 { |
| 1140 Py_ssize_t res; | 1140 Py_ssize_t res; |
| 1141 if (v == Py_True) | 1141 if (v == Py_True) |
| 1142 return 1; | 1142 return 1; |
| 1143 if (v == Py_False) | 1143 if (v == Py_False) |
| 1144 return 0; | |
| 1145 if (v == Py_None) | |
| 1146 return 0; | 1144 return 0; |
| 1147 else if (v->ob_type->tp_as_number != NULL && | 1145 else if (v->ob_type->tp_as_number != NULL && |
| 1148 v->ob_type->tp_as_number->nb_bool != NULL) | 1146 v->ob_type->tp_as_number->nb_bool != NULL) |
| 1149 res = (*v->ob_type->tp_as_number->nb_bool)(v); | 1147 res = (*v->ob_type->tp_as_number->nb_bool)(v); |
| 1150 else if (v->ob_type->tp_as_mapping != NULL && | 1148 else if (v->ob_type->tp_as_mapping != NULL && |
| 1151 v->ob_type->tp_as_mapping->mp_length != NULL) | 1149 v->ob_type->tp_as_mapping->mp_length != NULL) |
| 1152 res = (*v->ob_type->tp_as_mapping->mp_length)(v); | 1150 res = (*v->ob_type->tp_as_mapping->mp_length)(v); |
| 1153 else if (v->ob_type->tp_as_sequence != NULL && | 1151 else if (v->ob_type->tp_as_sequence != NULL && |
| 1154 v->ob_type->tp_as_sequence->sq_length != NULL) | 1152 v->ob_type->tp_as_sequence->sq_length != NULL) |
| 1155 res = (*v->ob_type->tp_as_sequence->sq_length)(v); | 1153 res = (*v->ob_type->tp_as_sequence->sq_length)(v); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1270 /* ARGUSED */ | 1268 /* ARGUSED */ |
| 1271 static void | 1269 static void |
| 1272 none_dealloc(PyObject* ignore) | 1270 none_dealloc(PyObject* ignore) |
| 1273 { | 1271 { |
| 1274 /* This should never get called, but we also don't want to SEGV if | 1272 /* This should never get called, but we also don't want to SEGV if |
| 1275 * we accidentally decref None out of existence. | 1273 * we accidentally decref None out of existence. |
| 1276 */ | 1274 */ |
| 1277 Py_FatalError("deallocating None"); | 1275 Py_FatalError("deallocating None"); |
| 1278 } | 1276 } |
| 1279 | 1277 |
| 1278 static int |
| 1279 none_bool(PyObject *v) |
| 1280 { |
| 1281 return 0; |
| 1282 } |
| 1283 |
| 1284 static PyNumberMethods none_as_number = { |
| 1285 0, /* nb_add */ |
| 1286 0, /* nb_subtract */ |
| 1287 0, /* nb_multiply */ |
| 1288 0, /* nb_remainder */ |
| 1289 0, /* nb_divmod */ |
| 1290 0, /* nb_power */ |
| 1291 0, /* nb_negative */ |
| 1292 0, /* nb_positive */ |
| 1293 0, /* nb_absolute */ |
| 1294 (inquiry)none_bool, /* nb_bool */ |
| 1295 0, /* nb_invert */ |
| 1296 0, /* nb_lshift */ |
| 1297 0, /* nb_rshift */ |
| 1298 0, /* nb_and */ |
| 1299 0, /* nb_xor */ |
| 1300 0, /* nb_or */ |
| 1301 0, /* nb_int */ |
| 1302 0, /* nb_reserved */ |
| 1303 0, /* nb_float */ |
| 1304 0, /* nb_inplace_add */ |
| 1305 0, /* nb_inplace_subtract */ |
| 1306 0, /* nb_inplace_multiply */ |
| 1307 0, /* nb_inplace_remainder */ |
| 1308 0, /* nb_inplace_power */ |
| 1309 0, /* nb_inplace_lshift */ |
| 1310 0, /* nb_inplace_rshift */ |
| 1311 0, /* nb_inplace_and */ |
| 1312 0, /* nb_inplace_xor */ |
| 1313 0, /* nb_inplace_or */ |
| 1314 0, /* nb_floor_divide */ |
| 1315 0, /* nb_true_divide */ |
| 1316 0, /* nb_inplace_floor_divide */ |
| 1317 0, /* nb_inplace_true_divide */ |
| 1318 0, /* nb_index */ |
| 1319 }; |
| 1280 | 1320 |
| 1281 static PyTypeObject PyNone_Type = { | 1321 static PyTypeObject PyNone_Type = { |
| 1282 PyVarObject_HEAD_INIT(&PyType_Type, 0) | 1322 PyVarObject_HEAD_INIT(&PyType_Type, 0) |
| 1283 "NoneType", | 1323 "NoneType", |
| 1284 0, | 1324 0, |
| 1285 0, | 1325 0, |
| 1286 none_dealloc, /*tp_dealloc*/ /*never called*/ | 1326 none_dealloc, /*tp_dealloc*/ /*never called*/ |
| 1287 0, /*tp_print*/ | 1327 0, /*tp_print*/ |
| 1288 0, /*tp_getattr*/ | 1328 0, /*tp_getattr*/ |
| 1289 0, /*tp_setattr*/ | 1329 0, /*tp_setattr*/ |
| 1290 0, /*tp_reserved*/ | 1330 0, /*tp_reserved*/ |
| 1291 none_repr, /*tp_repr*/ | 1331 none_repr, /*tp_repr*/ |
| 1292 0, /*tp_as_number*/ | 1332 &none_as_number, /*tp_as_number*/ |
| 1293 0, /*tp_as_sequence*/ | 1333 0, /*tp_as_sequence*/ |
| 1294 0, /*tp_as_mapping*/ | 1334 0, /*tp_as_mapping*/ |
| 1295 0, /*tp_hash */ | 1335 0, /*tp_hash */ |
| 1296 }; | 1336 }; |
| 1297 | 1337 |
| 1298 PyObject _Py_NoneStruct = { | 1338 PyObject _Py_NoneStruct = { |
| 1299 _PyObject_EXTRA_INIT | 1339 _PyObject_EXTRA_INIT |
| 1300 1, &PyNone_Type | 1340 1, &PyNone_Type |
| 1301 }; | 1341 }; |
| 1302 | 1342 |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1732 _Py_Dealloc(PyObject *op) | 1772 _Py_Dealloc(PyObject *op) |
| 1733 { | 1773 { |
| 1734 _Py_INC_TPFREES(op) _Py_COUNT_ALLOCS_COMMA | 1774 _Py_INC_TPFREES(op) _Py_COUNT_ALLOCS_COMMA |
| 1735 (*Py_TYPE(op)->tp_dealloc)(op); | 1775 (*Py_TYPE(op)->tp_dealloc)(op); |
| 1736 } | 1776 } |
| 1737 #endif | 1777 #endif |
| 1738 | 1778 |
| 1739 #ifdef __cplusplus | 1779 #ifdef __cplusplus |
| 1740 } | 1780 } |
| 1741 #endif | 1781 #endif |
| OLD | NEW |