| 1238 | #define Py_CONSTANT_EMPTY_TUPLE 9 |
| 1239 | |
| 1240 | static inline PyObject* Py_GetConstant(unsigned int constant_id) |
| 1241 | { |
| 1242 | static PyObject* constants[Py_CONSTANT_EMPTY_TUPLE + 1] = {NULL}; |
| 1243 | |
| 1244 | if (constants[Py_CONSTANT_NONE] == NULL) { |
| 1245 | constants[Py_CONSTANT_NONE] = Py_None; |
| 1246 | constants[Py_CONSTANT_FALSE] = Py_False; |
| 1247 | constants[Py_CONSTANT_TRUE] = Py_True; |
| 1248 | constants[Py_CONSTANT_ELLIPSIS] = Py_Ellipsis; |
| 1249 | constants[Py_CONSTANT_NOT_IMPLEMENTED] = Py_NotImplemented; |
| 1250 | |
| 1251 | constants[Py_CONSTANT_ZERO] = PyLong_FromLong(0); |
| 1252 | if (constants[Py_CONSTANT_ZERO] == NULL) { |
| 1253 | goto fatal_error; |
| 1254 | } |
| 1255 | |
| 1256 | constants[Py_CONSTANT_ONE] = PyLong_FromLong(1); |
| 1257 | if (constants[Py_CONSTANT_ONE] == NULL) { |
| 1258 | goto fatal_error; |
| 1259 | } |
| 1260 | |
| 1261 | constants[Py_CONSTANT_EMPTY_STR] = PyUnicode_FromStringAndSize("", 0); |
| 1262 | if (constants[Py_CONSTANT_EMPTY_STR] == NULL) { |
| 1263 | goto fatal_error; |
| 1264 | } |
| 1265 | |
| 1266 | constants[Py_CONSTANT_EMPTY_BYTES] = PyBytes_FromStringAndSize("", 0); |
| 1267 | if (constants[Py_CONSTANT_EMPTY_BYTES] == NULL) { |
| 1268 | goto fatal_error; |
| 1269 | } |
| 1270 | |
| 1271 | constants[Py_CONSTANT_EMPTY_TUPLE] = PyTuple_New(0); |
| 1272 | if (constants[Py_CONSTANT_EMPTY_TUPLE] == NULL) { |
| 1273 | goto fatal_error; |
| 1274 | } |
| 1275 | // goto dance to avoid compiler warnings about Py_FatalError() |
| 1276 | goto init_done; |
| 1277 | |
| 1278 | fatal_error: |
| 1279 | // This case should never happen |
| 1280 | Py_FatalError("Py_GetConstant() failed to get constants"); |
| 1281 | } |
| 1282 | |
| 1283 | init_done: |
| 1284 | if (constant_id <= Py_CONSTANT_EMPTY_TUPLE) { |
| 1285 | return Py_NewRef(constants[constant_id]); |
| 1286 | } |
| 1287 | else { |
| 1288 | PyErr_BadInternalCall(); |
| 1289 | return NULL; |
| 1290 | } |
| 1291 | } |
| 1292 | |
| 1293 | static inline PyObject* Py_GetConstantBorrowed(unsigned int constant_id) |
| 1294 | { |
no outgoing calls
no test coverage detected