|
7 | 7 | #ifndef Py_BUILD_CORE_BUILTIN
|
8 | 8 | # define Py_BUILD_CORE_MODULE 1
|
9 | 9 | #endif
|
10 |
| -#define NEEDS_PY_IDENTIFIER |
11 | 10 |
|
12 | 11 | #include "Python.h"
|
13 | 12 | #include "pycore_ceval.h" // _Py_EnterRecursiveCall()
|
14 | 13 | #include "structmember.h" // PyMemberDef
|
| 14 | +#include "pycore_runtime_init.h" // _Py_ID() |
15 | 15 | #include <stdbool.h> // bool
|
16 | 16 |
|
17 | 17 |
|
@@ -305,15 +305,9 @@ static void
|
305 | 305 | raise_errmsg(const char *msg, PyObject *s, Py_ssize_t end)
|
306 | 306 | {
|
307 | 307 | /* Use JSONDecodeError exception to raise a nice looking ValueError subclass */
|
308 |
| - _Py_static_string(PyId_decoder, "json.decoder"); |
309 |
| - PyObject *decoder = _PyImport_GetModuleId(&PyId_decoder); |
310 |
| - if (decoder == NULL) { |
311 |
| - return; |
312 |
| - } |
313 |
| - |
314 |
| - _Py_IDENTIFIER(JSONDecodeError); |
315 |
| - PyObject *JSONDecodeError = _PyObject_GetAttrId(decoder, &PyId_JSONDecodeError); |
316 |
| - Py_DECREF(decoder); |
| 308 | + _Py_DECLARE_STR(json_decoder, "json.decoder"); |
| 309 | + PyObject *JSONDecodeError = |
| 310 | + _PyImport_GetModuleAttr(&_Py_STR(json_decoder), &_Py_ID(JSONDecodeError)); |
317 | 311 | if (JSONDecodeError == NULL) {
|
318 | 312 | return;
|
319 | 313 | }
|
@@ -1310,28 +1304,13 @@ _encoded_const(PyObject *obj)
|
1310 | 1304 | {
|
1311 | 1305 | /* Return the JSON string representation of None, True, False */
|
1312 | 1306 | if (obj == Py_None) {
|
1313 |
| - _Py_static_string(PyId_null, "null"); |
1314 |
| - PyObject *s_null = _PyUnicode_FromId(&PyId_null); |
1315 |
| - if (s_null == NULL) { |
1316 |
| - return NULL; |
1317 |
| - } |
1318 |
| - return Py_NewRef(s_null); |
| 1307 | + return Py_NewRef(&_Py_ID(null)); |
1319 | 1308 | }
|
1320 | 1309 | else if (obj == Py_True) {
|
1321 |
| - _Py_static_string(PyId_true, "true"); |
1322 |
| - PyObject *s_true = _PyUnicode_FromId(&PyId_true); |
1323 |
| - if (s_true == NULL) { |
1324 |
| - return NULL; |
1325 |
| - } |
1326 |
| - return Py_NewRef(s_true); |
| 1310 | + return Py_NewRef(&_Py_ID(true)); |
1327 | 1311 | }
|
1328 | 1312 | else if (obj == Py_False) {
|
1329 |
| - _Py_static_string(PyId_false, "false"); |
1330 |
| - PyObject *s_false = _PyUnicode_FromId(&PyId_false); |
1331 |
| - if (s_false == NULL) { |
1332 |
| - return NULL; |
1333 |
| - } |
1334 |
| - return Py_NewRef(s_false); |
| 1313 | + return Py_NewRef(&_Py_ID(false)); |
1335 | 1314 | }
|
1336 | 1315 | else {
|
1337 | 1316 | PyErr_SetString(PyExc_ValueError, "not a const");
|
@@ -1530,7 +1509,7 @@ encoder_encode_key_value(PyEncoderObject *s, _PyUnicodeWriter *writer, bool *fir
|
1530 | 1509 |
|
1531 | 1510 | if (*first) {
|
1532 | 1511 | *first = false;
|
1533 |
| - } |
| 1512 | + } |
1534 | 1513 | else {
|
1535 | 1514 | if (_PyUnicodeWriter_WriteStr(writer, s->item_separator) < 0) {
|
1536 | 1515 | Py_DECREF(keystr);
|
|
0 commit comments