diff options
author | Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> | 2022-11-02 16:03:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-02 16:03:38 (GMT) |
commit | 780757ac586d7275db5ee1f229fb2f3d2268d14e (patch) | |
tree | 3e769327a6ea11c2baaac45c3067562f936c49e7 /Modules/_json.c | |
parent | df84b7b0bce36d94e90f368b55c9268d5b641dc9 (diff) | |
download | cpython-780757ac586d7275db5ee1f229fb2f3d2268d14e.zip cpython-780757ac586d7275db5ee1f229fb2f3d2268d14e.tar.gz cpython-780757ac586d7275db5ee1f229fb2f3d2268d14e.tar.bz2 |
GH-90699: Remove `_Py_IDENTIFIER` usage from `_json` module (GH-98956)
Diffstat (limited to 'Modules/_json.c')
-rw-r--r-- | Modules/_json.c | 37 |
1 files changed, 8 insertions, 29 deletions
diff --git a/Modules/_json.c b/Modules/_json.c index 1c39b46..fe86951 100644 --- a/Modules/_json.c +++ b/Modules/_json.c @@ -7,11 +7,11 @@ #ifndef Py_BUILD_CORE_BUILTIN # define Py_BUILD_CORE_MODULE 1 #endif -#define NEEDS_PY_IDENTIFIER #include "Python.h" #include "pycore_ceval.h" // _Py_EnterRecursiveCall() #include "structmember.h" // PyMemberDef +#include "pycore_runtime_init.h" // _Py_ID() #include <stdbool.h> // bool @@ -305,15 +305,9 @@ static void raise_errmsg(const char *msg, PyObject *s, Py_ssize_t end) { /* Use JSONDecodeError exception to raise a nice looking ValueError subclass */ - _Py_static_string(PyId_decoder, "json.decoder"); - PyObject *decoder = _PyImport_GetModuleId(&PyId_decoder); - if (decoder == NULL) { - return; - } - - _Py_IDENTIFIER(JSONDecodeError); - PyObject *JSONDecodeError = _PyObject_GetAttrId(decoder, &PyId_JSONDecodeError); - Py_DECREF(decoder); + _Py_DECLARE_STR(json_decoder, "json.decoder"); + PyObject *JSONDecodeError = + _PyImport_GetModuleAttr(&_Py_STR(json_decoder), &_Py_ID(JSONDecodeError)); if (JSONDecodeError == NULL) { return; } @@ -1310,28 +1304,13 @@ _encoded_const(PyObject *obj) { /* Return the JSON string representation of None, True, False */ if (obj == Py_None) { - _Py_static_string(PyId_null, "null"); - PyObject *s_null = _PyUnicode_FromId(&PyId_null); - if (s_null == NULL) { - return NULL; - } - return Py_NewRef(s_null); + return Py_NewRef(&_Py_ID(null)); } else if (obj == Py_True) { - _Py_static_string(PyId_true, "true"); - PyObject *s_true = _PyUnicode_FromId(&PyId_true); - if (s_true == NULL) { - return NULL; - } - return Py_NewRef(s_true); + return Py_NewRef(&_Py_ID(true)); } else if (obj == Py_False) { - _Py_static_string(PyId_false, "false"); - PyObject *s_false = _PyUnicode_FromId(&PyId_false); - if (s_false == NULL) { - return NULL; - } - return Py_NewRef(s_false); + return Py_NewRef(&_Py_ID(false)); } else { PyErr_SetString(PyExc_ValueError, "not a const"); @@ -1530,7 +1509,7 @@ encoder_encode_key_value(PyEncoderObject *s, _PyUnicodeWriter *writer, bool *fir if (*first) { *first = false; - } + } else { if (_PyUnicodeWriter_WriteStr(writer, s->item_separator) < 0) { Py_DECREF(keystr); |