summaryrefslogtreecommitdiffstats
path: root/Modules/_json.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-11-14 12:08:43 (GMT)
committerGitHub <noreply@github.com>2022-11-14 12:08:43 (GMT)
commit7e4dec02ac86bcbe958f299f68ed25d543c23ef9 (patch)
treebc9999d57707f92f6dc390fed16af10f71e29ddb /Modules/_json.c
parent3817607b8a345851e4fa436747a346890ced33f1 (diff)
downloadcpython-7e4dec02ac86bcbe958f299f68ed25d543c23ef9.zip
cpython-7e4dec02ac86bcbe958f299f68ed25d543c23ef9.tar.gz
cpython-7e4dec02ac86bcbe958f299f68ed25d543c23ef9.tar.bz2
gh-99300: Use Py_NewRef() in Modules/ directory (#99467)
Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and Py_XNewRef() in test C files of the Modules/ directory.
Diffstat (limited to 'Modules/_json.c')
-rw-r--r--Modules/_json.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/Modules/_json.c b/Modules/_json.c
index 82f960f..06f232f 100644
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -1243,16 +1243,17 @@ encoder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (s == NULL)
return NULL;
- s->markers = markers;
- s->defaultfn = defaultfn;
- s->encoder = encoder;
- s->indent = indent;
- s->key_separator = key_separator;
- s->item_separator = item_separator;
+ s->markers = Py_NewRef(markers);
+ s->defaultfn = Py_NewRef(defaultfn);
+ s->encoder = Py_NewRef(encoder);
+ s->indent = Py_NewRef(indent);
+ s->key_separator = Py_NewRef(key_separator);
+ s->item_separator = Py_NewRef(item_separator);
s->sort_keys = sort_keys;
s->skipkeys = skipkeys;
s->allow_nan = allow_nan;
s->fast_encode = NULL;
+
if (PyCFunction_Check(s->encoder)) {
PyCFunction f = PyCFunction_GetFunction(s->encoder);
if (f == (PyCFunction)py_encode_basestring_ascii ||
@@ -1261,12 +1262,6 @@ encoder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
}
- Py_INCREF(s->markers);
- Py_INCREF(s->defaultfn);
- Py_INCREF(s->encoder);
- Py_INCREF(s->indent);
- Py_INCREF(s->key_separator);
- Py_INCREF(s->item_separator);
return (PyObject *)s;
}
@@ -1480,8 +1475,7 @@ encoder_encode_key_value(PyEncoderObject *s, _PyUnicodeWriter *writer, bool *fir
PyObject *encoded;
if (PyUnicode_Check(key)) {
- Py_INCREF(key);
- keystr = key;
+ keystr = Py_NewRef(key);
}
else if (PyFloat_Check(key)) {
keystr = encoder_encode_float(s, key);