Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Include/internal/pycore_global_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(extend)
STRUCT_FOR_ID(facility)
STRUCT_FOR_ID(factory)
STRUCT_FOR_ID(false)
STRUCT_FOR_ID(family)
STRUCT_FOR_ID(fanout)
STRUCT_FOR_ID(fd)
Expand Down Expand Up @@ -491,6 +492,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(node_offset)
STRUCT_FOR_ID(ns)
STRUCT_FOR_ID(nstype)
STRUCT_FOR_ID(null)
STRUCT_FOR_ID(number)
STRUCT_FOR_ID(obj)
STRUCT_FOR_ID(object)
Expand Down Expand Up @@ -627,6 +629,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(traceback)
STRUCT_FOR_ID(trailers)
STRUCT_FOR_ID(translate)
STRUCT_FOR_ID(true)
STRUCT_FOR_ID(truncate)
STRUCT_FOR_ID(twice)
STRUCT_FOR_ID(txt)
Expand Down
21 changes: 21 additions & 0 deletions Include/internal/pycore_runtime_init_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 7 additions & 29 deletions Modules/_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -305,15 +305,8 @@ 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);
PyObject *JSONDecodeError =
_PyImport_GetModuleAttrString("json.decoder", "JSONDecodeError");
if (JSONDecodeError == NULL) {
return;
}
Expand Down Expand Up @@ -1310,28 +1303,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");
Expand Down Expand Up @@ -1530,7 +1508,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);
Expand Down