mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
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.
This commit is contained in:
parent
3817607b8a
commit
7e4dec02ac
10 changed files with 75 additions and 144 deletions
|
@ -212,8 +212,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
|
||||||
is_number = PyNumber_Check(file);
|
is_number = PyNumber_Check(file);
|
||||||
|
|
||||||
if (is_number) {
|
if (is_number) {
|
||||||
path_or_fd = file;
|
path_or_fd = Py_NewRef(file);
|
||||||
Py_INCREF(path_or_fd);
|
|
||||||
} else {
|
} else {
|
||||||
path_or_fd = PyOS_FSPath(file);
|
path_or_fd = PyOS_FSPath(file);
|
||||||
if (path_or_fd == NULL) {
|
if (path_or_fd == NULL) {
|
||||||
|
@ -489,8 +488,7 @@ _io_text_encoding_impl(PyObject *module, PyObject *encoding, int stacklevel)
|
||||||
encoding = &_Py_ID(locale);
|
encoding = &_Py_ID(locale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Py_INCREF(encoding);
|
return Py_NewRef(encoding);
|
||||||
return encoding;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -697,9 +695,8 @@ PyInit__io(void)
|
||||||
"UnsupportedOperation", PyExc_OSError, PyExc_ValueError);
|
"UnsupportedOperation", PyExc_OSError, PyExc_ValueError);
|
||||||
if (state->unsupported_operation == NULL)
|
if (state->unsupported_operation == NULL)
|
||||||
goto fail;
|
goto fail;
|
||||||
Py_INCREF(state->unsupported_operation);
|
|
||||||
if (PyModule_AddObject(m, "UnsupportedOperation",
|
if (PyModule_AddObject(m, "UnsupportedOperation",
|
||||||
state->unsupported_operation) < 0)
|
Py_NewRef(state->unsupported_operation)) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
/* BlockingIOError, for compatibility */
|
/* BlockingIOError, for compatibility */
|
||||||
|
|
|
@ -481,8 +481,7 @@ buffered_close(buffered *self, PyObject *args)
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto end;
|
goto end;
|
||||||
if (r > 0) {
|
if (r > 0) {
|
||||||
res = Py_None;
|
res = Py_NewRef(Py_None);
|
||||||
Py_INCREF(res);
|
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1007,8 +1006,7 @@ _buffered_readinto_generic(buffered *self, Py_buffer *buffer, char readinto1)
|
||||||
break;
|
break;
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
if (n == -2) {
|
if (n == -2) {
|
||||||
Py_INCREF(Py_None);
|
res = Py_NewRef(Py_None);
|
||||||
res = Py_None;
|
|
||||||
}
|
}
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
@ -1422,8 +1420,7 @@ _io_BufferedReader___init___impl(buffered *self, PyObject *raw,
|
||||||
if (_PyIOBase_check_readable(raw, Py_True) == NULL)
|
if (_PyIOBase_check_readable(raw, Py_True) == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
Py_INCREF(raw);
|
Py_XSETREF(self->raw, Py_NewRef(raw));
|
||||||
Py_XSETREF(self->raw, raw);
|
|
||||||
self->buffer_size = buffer_size;
|
self->buffer_size = buffer_size;
|
||||||
self->readable = 1;
|
self->readable = 1;
|
||||||
self->writable = 0;
|
self->writable = 0;
|
||||||
|
|
|
@ -324,8 +324,7 @@ _io_BytesIO_getbuffer_impl(bytesio *self)
|
||||||
buf = (bytesiobuf *) type->tp_alloc(type, 0);
|
buf = (bytesiobuf *) type->tp_alloc(type, 0);
|
||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
Py_INCREF(self);
|
buf->source = (bytesio*)Py_NewRef(self);
|
||||||
buf->source = self;
|
|
||||||
view = PyMemoryView_FromObject((PyObject *) buf);
|
view = PyMemoryView_FromObject((PyObject *) buf);
|
||||||
Py_DECREF(buf);
|
Py_DECREF(buf);
|
||||||
return view;
|
return view;
|
||||||
|
@ -356,8 +355,7 @@ _io_BytesIO_getvalue_impl(bytesio *self)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Py_INCREF(self->buf);
|
return Py_NewRef(self->buf);
|
||||||
return self->buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*[clinic input]
|
/*[clinic input]
|
||||||
|
@ -401,8 +399,7 @@ read_bytes(bytesio *self, Py_ssize_t size)
|
||||||
self->pos == 0 && size == PyBytes_GET_SIZE(self->buf) &&
|
self->pos == 0 && size == PyBytes_GET_SIZE(self->buf) &&
|
||||||
self->exports == 0) {
|
self->exports == 0) {
|
||||||
self->pos += size;
|
self->pos += size;
|
||||||
Py_INCREF(self->buf);
|
return Py_NewRef(self->buf);
|
||||||
return self->buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
output = PyBytes_AS_STRING(self->buf) + self->pos;
|
output = PyBytes_AS_STRING(self->buf) + self->pos;
|
||||||
|
@ -791,8 +788,7 @@ bytesio_getstate(bytesio *self, PyObject *Py_UNUSED(ignored))
|
||||||
if (initvalue == NULL)
|
if (initvalue == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (self->dict == NULL) {
|
if (self->dict == NULL) {
|
||||||
Py_INCREF(Py_None);
|
dict = Py_NewRef(Py_None);
|
||||||
dict = Py_None;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
dict = PyDict_Copy(self->dict);
|
dict = PyDict_Copy(self->dict);
|
||||||
|
@ -875,8 +871,7 @@ bytesio_setstate(bytesio *self, PyObject *state)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Py_INCREF(dict);
|
self->dict = Py_NewRef(dict);
|
||||||
self->dict = dict;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -943,8 +938,7 @@ _io_BytesIO___init___impl(bytesio *self, PyObject *initvalue)
|
||||||
}
|
}
|
||||||
if (initvalue && initvalue != Py_None) {
|
if (initvalue && initvalue != Py_None) {
|
||||||
if (PyBytes_CheckExact(initvalue)) {
|
if (PyBytes_CheckExact(initvalue)) {
|
||||||
Py_INCREF(initvalue);
|
Py_XSETREF(self->buf, Py_NewRef(initvalue));
|
||||||
Py_XSETREF(self->buf, initvalue);
|
|
||||||
self->string_size = PyBytes_GET_SIZE(initvalue);
|
self->string_size = PyBytes_GET_SIZE(initvalue);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -464,8 +464,7 @@ iobase_enter(PyObject *self, PyObject *args)
|
||||||
if (iobase_check_closed(self))
|
if (iobase_check_closed(self))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
Py_INCREF(self);
|
return Py_NewRef(self);
|
||||||
return self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -642,8 +641,7 @@ iobase_iter(PyObject *self)
|
||||||
if (iobase_check_closed(self))
|
if (iobase_check_closed(self))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
Py_INCREF(self);
|
return Py_NewRef(self);
|
||||||
return self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
|
@ -188,8 +188,7 @@ write_str(stringio *self, PyObject *obj)
|
||||||
self->decoder, obj, 1 /* always final */);
|
self->decoder, obj, 1 /* always final */);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
decoded = obj;
|
decoded = Py_NewRef(obj);
|
||||||
Py_INCREF(decoded);
|
|
||||||
}
|
}
|
||||||
if (self->writenl) {
|
if (self->writenl) {
|
||||||
PyObject *translated = PyUnicode_Replace(
|
PyObject *translated = PyUnicode_Replace(
|
||||||
|
@ -710,8 +709,7 @@ _io_StringIO___init___impl(stringio *self, PyObject *value,
|
||||||
is pointless for StringIO)
|
is pointless for StringIO)
|
||||||
*/
|
*/
|
||||||
if (newline != NULL && newline[0] == '\r') {
|
if (newline != NULL && newline[0] == '\r') {
|
||||||
self->writenl = self->readnl;
|
self->writenl = Py_NewRef(self->readnl);
|
||||||
Py_INCREF(self->writenl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self->readuniversal) {
|
if (self->readuniversal) {
|
||||||
|
@ -823,8 +821,7 @@ stringio_getstate(stringio *self, PyObject *Py_UNUSED(ignored))
|
||||||
if (initvalue == NULL)
|
if (initvalue == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (self->dict == NULL) {
|
if (self->dict == NULL) {
|
||||||
Py_INCREF(Py_None);
|
dict = Py_NewRef(Py_None);
|
||||||
dict = Py_None;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
dict = PyDict_Copy(self->dict);
|
dict = PyDict_Copy(self->dict);
|
||||||
|
@ -934,8 +931,7 @@ stringio_setstate(stringio *self, PyObject *state)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Py_INCREF(dict);
|
self->dict = Py_NewRef(dict);
|
||||||
self->dict = dict;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -231,16 +231,14 @@ _io_IncrementalNewlineDecoder___init___impl(nldecoder_object *self,
|
||||||
PyObject *errors)
|
PyObject *errors)
|
||||||
/*[clinic end generated code: output=fbd04d443e764ec2 input=89db6b19c6b126bf]*/
|
/*[clinic end generated code: output=fbd04d443e764ec2 input=89db6b19c6b126bf]*/
|
||||||
{
|
{
|
||||||
self->decoder = decoder;
|
self->decoder = Py_NewRef(decoder);
|
||||||
Py_INCREF(decoder);
|
|
||||||
|
|
||||||
if (errors == NULL) {
|
if (errors == NULL) {
|
||||||
self->errors = &_Py_ID(strict);
|
self->errors = Py_NewRef(&_Py_ID(strict));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
self->errors = errors;
|
self->errors = Py_NewRef(errors);
|
||||||
}
|
}
|
||||||
Py_INCREF(self->errors);
|
|
||||||
|
|
||||||
self->translate = translate ? 1 : 0;
|
self->translate = translate ? 1 : 0;
|
||||||
self->seennl = 0;
|
self->seennl = 0;
|
||||||
|
@ -301,8 +299,7 @@ _PyIncrementalNewlineDecoder_decode(PyObject *myself,
|
||||||
&_Py_ID(decode), input, final ? Py_True : Py_False, NULL);
|
&_Py_ID(decode), input, final ? Py_True : Py_False, NULL);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
output = input;
|
output = Py_NewRef(input);
|
||||||
Py_INCREF(output);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (check_decoded(output) < 0)
|
if (check_decoded(output) < 0)
|
||||||
|
@ -1148,8 +1145,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
|
||||||
* of the partially constructed object (like self->encoding)
|
* of the partially constructed object (like self->encoding)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Py_INCREF(errors);
|
self->errors = Py_NewRef(errors);
|
||||||
self->errors = errors;
|
|
||||||
self->chunk_size = 8192;
|
self->chunk_size = 8192;
|
||||||
self->line_buffering = line_buffering;
|
self->line_buffering = line_buffering;
|
||||||
self->write_through = write_through;
|
self->write_through = write_through;
|
||||||
|
@ -1157,8 +1153,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
self->buffer = buffer;
|
self->buffer = Py_NewRef(buffer);
|
||||||
Py_INCREF(buffer);
|
|
||||||
|
|
||||||
/* Build the decoder object */
|
/* Build the decoder object */
|
||||||
if (_textiowrapper_set_decoder(self, codec_info, PyUnicode_AsUTF8(errors)) != 0)
|
if (_textiowrapper_set_decoder(self, codec_info, PyUnicode_AsUTF8(errors)) != 0)
|
||||||
|
@ -1284,9 +1279,8 @@ textiowrapper_change_encoding(textio *self, PyObject *encoding,
|
||||||
}
|
}
|
||||||
Py_DECREF(codec_info);
|
Py_DECREF(codec_info);
|
||||||
|
|
||||||
Py_INCREF(errors);
|
|
||||||
Py_SETREF(self->encoding, encoding);
|
Py_SETREF(self->encoding, encoding);
|
||||||
Py_SETREF(self->errors, errors);
|
Py_SETREF(self->errors, Py_NewRef(errors));
|
||||||
|
|
||||||
return _textiowrapper_fix_encoder_state(self);
|
return _textiowrapper_fix_encoder_state(self);
|
||||||
}
|
}
|
||||||
|
@ -1502,8 +1496,7 @@ _textiowrapper_writeflush(textio *self)
|
||||||
PyObject *b;
|
PyObject *b;
|
||||||
|
|
||||||
if (PyBytes_Check(pending)) {
|
if (PyBytes_Check(pending)) {
|
||||||
b = pending;
|
b = Py_NewRef(pending);
|
||||||
Py_INCREF(b);
|
|
||||||
}
|
}
|
||||||
else if (PyUnicode_Check(pending)) {
|
else if (PyUnicode_Check(pending)) {
|
||||||
assert(PyUnicode_IS_ASCII(pending));
|
assert(PyUnicode_IS_ASCII(pending));
|
||||||
|
@ -1618,8 +1611,7 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text)
|
||||||
// See bpo-43260
|
// See bpo-43260
|
||||||
PyUnicode_GET_LENGTH(text) <= self->chunk_size &&
|
PyUnicode_GET_LENGTH(text) <= self->chunk_size &&
|
||||||
is_asciicompat_encoding(self->encodefunc)) {
|
is_asciicompat_encoding(self->encodefunc)) {
|
||||||
b = text;
|
b = Py_NewRef(text);
|
||||||
Py_INCREF(b);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
b = (*self->encodefunc)((PyObject *) self, text);
|
b = (*self->encodefunc)((PyObject *) self, text);
|
||||||
|
@ -1741,8 +1733,7 @@ textiowrapper_get_decoded_chars(textio *self, Py_ssize_t n)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
chars = self->decoded_chars;
|
chars = Py_NewRef(self->decoded_chars);
|
||||||
Py_INCREF(chars);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self->decoded_chars_used += n;
|
self->decoded_chars_used += n;
|
||||||
|
@ -2139,10 +2130,9 @@ _textiowrapper_readline(textio *self, Py_ssize_t limit)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remaining == NULL) {
|
if (remaining == NULL) {
|
||||||
line = self->decoded_chars;
|
line = Py_NewRef(self->decoded_chars);
|
||||||
start = self->decoded_chars_used;
|
start = self->decoded_chars_used;
|
||||||
offset_to_buffer = 0;
|
offset_to_buffer = 0;
|
||||||
Py_INCREF(line);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assert(self->decoded_chars_used == 0);
|
assert(self->decoded_chars_used == 0);
|
||||||
|
@ -3115,8 +3105,7 @@ static PyObject *
|
||||||
textiowrapper_errors_get(textio *self, void *context)
|
textiowrapper_errors_get(textio *self, void *context)
|
||||||
{
|
{
|
||||||
CHECK_INITIALIZED(self);
|
CHECK_INITIALIZED(self);
|
||||||
Py_INCREF(self->errors);
|
return Py_NewRef(self->errors);
|
||||||
return self->errors;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
|
@ -1243,16 +1243,17 @@ encoder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
s->markers = markers;
|
s->markers = Py_NewRef(markers);
|
||||||
s->defaultfn = defaultfn;
|
s->defaultfn = Py_NewRef(defaultfn);
|
||||||
s->encoder = encoder;
|
s->encoder = Py_NewRef(encoder);
|
||||||
s->indent = indent;
|
s->indent = Py_NewRef(indent);
|
||||||
s->key_separator = key_separator;
|
s->key_separator = Py_NewRef(key_separator);
|
||||||
s->item_separator = item_separator;
|
s->item_separator = Py_NewRef(item_separator);
|
||||||
s->sort_keys = sort_keys;
|
s->sort_keys = sort_keys;
|
||||||
s->skipkeys = skipkeys;
|
s->skipkeys = skipkeys;
|
||||||
s->allow_nan = allow_nan;
|
s->allow_nan = allow_nan;
|
||||||
s->fast_encode = NULL;
|
s->fast_encode = NULL;
|
||||||
|
|
||||||
if (PyCFunction_Check(s->encoder)) {
|
if (PyCFunction_Check(s->encoder)) {
|
||||||
PyCFunction f = PyCFunction_GetFunction(s->encoder);
|
PyCFunction f = PyCFunction_GetFunction(s->encoder);
|
||||||
if (f == (PyCFunction)py_encode_basestring_ascii ||
|
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;
|
return (PyObject *)s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1480,8 +1475,7 @@ encoder_encode_key_value(PyEncoderObject *s, _PyUnicodeWriter *writer, bool *fir
|
||||||
PyObject *encoded;
|
PyObject *encoded;
|
||||||
|
|
||||||
if (PyUnicode_Check(key)) {
|
if (PyUnicode_Check(key)) {
|
||||||
Py_INCREF(key);
|
keystr = Py_NewRef(key);
|
||||||
keystr = key;
|
|
||||||
}
|
}
|
||||||
else if (PyFloat_Check(key)) {
|
else if (PyFloat_Check(key)) {
|
||||||
keystr = encoder_encode_float(s, key);
|
keystr = encoder_encode_float(s, key);
|
||||||
|
|
|
@ -128,8 +128,7 @@ normalizeUserObj(PyObject *obj)
|
||||||
{
|
{
|
||||||
PyCFunctionObject *fn;
|
PyCFunctionObject *fn;
|
||||||
if (!PyCFunction_Check(obj)) {
|
if (!PyCFunction_Check(obj)) {
|
||||||
Py_INCREF(obj);
|
return Py_NewRef(obj);
|
||||||
return obj;
|
|
||||||
}
|
}
|
||||||
/* Replace built-in function objects with a descriptive string
|
/* Replace built-in function objects with a descriptive string
|
||||||
because of built-in methods -- keeping a reference to
|
because of built-in methods -- keeping a reference to
|
||||||
|
@ -142,8 +141,7 @@ normalizeUserObj(PyObject *obj)
|
||||||
PyObject *modname = NULL;
|
PyObject *modname = NULL;
|
||||||
if (mod != NULL) {
|
if (mod != NULL) {
|
||||||
if (PyUnicode_Check(mod)) {
|
if (PyUnicode_Check(mod)) {
|
||||||
modname = mod;
|
modname = Py_NewRef(mod);
|
||||||
Py_INCREF(modname);
|
|
||||||
}
|
}
|
||||||
else if (PyModule_Check(mod)) {
|
else if (PyModule_Check(mod)) {
|
||||||
modname = PyModule_GetNameObject(mod);
|
modname = PyModule_GetNameObject(mod);
|
||||||
|
@ -555,8 +553,7 @@ static int statsForEntry(rotating_node_t *node, void *arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Py_INCREF(Py_None);
|
collect->sublist = Py_NewRef(Py_None);
|
||||||
collect->sublist = Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
info = PyObject_CallFunction((PyObject*) collect->state->stats_entry_type,
|
info = PyObject_CallFunction((PyObject*) collect->state->stats_entry_type,
|
||||||
|
@ -781,8 +778,7 @@ profiler_init(ProfilerObject *pObj, PyObject *args, PyObject *kw)
|
||||||
if (setSubcalls(pObj, subcalls) < 0 || setBuiltins(pObj, builtins) < 0)
|
if (setSubcalls(pObj, subcalls) < 0 || setBuiltins(pObj, builtins) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
pObj->externalTimerUnit = timeunit;
|
pObj->externalTimerUnit = timeunit;
|
||||||
Py_XINCREF(timer);
|
Py_XSETREF(pObj->externalTimer, Py_XNewRef(timer));
|
||||||
Py_XSETREF(pObj->externalTimer, timer);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -722,8 +722,7 @@ _operator_is_not_impl(PyObject *module, PyObject *a, PyObject *b)
|
||||||
{
|
{
|
||||||
PyObject *result;
|
PyObject *result;
|
||||||
result = (a != b) ? Py_True : Py_False;
|
result = (a != b) ? Py_True : Py_False;
|
||||||
Py_INCREF(result);
|
return Py_NewRef(result);
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* compare_digest **********************************************************/
|
/* compare_digest **********************************************************/
|
||||||
|
@ -1010,8 +1009,7 @@ itemgetter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(item);
|
ig->item = Py_NewRef(item);
|
||||||
ig->item = item;
|
|
||||||
ig->nitems = nitems;
|
ig->nitems = nitems;
|
||||||
ig->index = -1;
|
ig->index = -1;
|
||||||
if (PyLong_CheckExact(item)) {
|
if (PyLong_CheckExact(item)) {
|
||||||
|
@ -1095,8 +1093,7 @@ itemgetter_call_impl(itemgetterobject *ig, PyObject *obj)
|
||||||
&& ig->index < PyTuple_GET_SIZE(obj))
|
&& ig->index < PyTuple_GET_SIZE(obj))
|
||||||
{
|
{
|
||||||
result = PyTuple_GET_ITEM(obj, ig->index);
|
result = PyTuple_GET_ITEM(obj, ig->index);
|
||||||
Py_INCREF(result);
|
return Py_NewRef(result);
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
return PyObject_GetItem(obj, ig->item);
|
return PyObject_GetItem(obj, ig->item);
|
||||||
}
|
}
|
||||||
|
@ -1440,8 +1437,7 @@ dotjoinattr(PyObject *attr, PyObject **attrsep)
|
||||||
}
|
}
|
||||||
return PyUnicode_Join(*attrsep, attr);
|
return PyUnicode_Join(*attrsep, attr);
|
||||||
} else {
|
} else {
|
||||||
Py_INCREF(attr);
|
return Py_NewRef(attr);
|
||||||
return attr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1594,8 +1590,7 @@ methodcaller_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
PyUnicode_InternInPlace(&name);
|
PyUnicode_InternInPlace(&name);
|
||||||
mc->name = name;
|
mc->name = name;
|
||||||
|
|
||||||
Py_XINCREF(kwds);
|
mc->kwds = Py_XNewRef(kwds);
|
||||||
mc->kwds = kwds;
|
|
||||||
|
|
||||||
mc->args = PyTuple_GetSlice(args, 1, PyTuple_GET_SIZE(args));
|
mc->args = PyTuple_GetSlice(args, 1, PyTuple_GET_SIZE(args));
|
||||||
if (mc->args == NULL) {
|
if (mc->args == NULL) {
|
||||||
|
@ -1740,12 +1735,10 @@ methodcaller_reduce(methodcallerobject *mc, PyObject *Py_UNUSED(ignored))
|
||||||
newargs = PyTuple_New(1 + callargcount);
|
newargs = PyTuple_New(1 + callargcount);
|
||||||
if (newargs == NULL)
|
if (newargs == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
Py_INCREF(mc->name);
|
PyTuple_SET_ITEM(newargs, 0, Py_NewRef(mc->name));
|
||||||
PyTuple_SET_ITEM(newargs, 0, mc->name);
|
|
||||||
for (i = 0; i < callargcount; ++i) {
|
for (i = 0; i < callargcount; ++i) {
|
||||||
PyObject *arg = PyTuple_GET_ITEM(mc->args, i);
|
PyObject *arg = PyTuple_GET_ITEM(mc->args, i);
|
||||||
Py_INCREF(arg);
|
PyTuple_SET_ITEM(newargs, i + 1, Py_NewRef(arg));
|
||||||
PyTuple_SET_ITEM(newargs, i + 1, arg);
|
|
||||||
}
|
}
|
||||||
return Py_BuildValue("ON", Py_TYPE(mc), newargs);
|
return Py_BuildValue("ON", Py_TYPE(mc), newargs);
|
||||||
}
|
}
|
||||||
|
|
|
@ -386,10 +386,9 @@ init_method_ref(PyObject *self, PyObject *name,
|
||||||
|
|
||||||
if (PyMethod_Check(func) && PyMethod_GET_SELF(func) == self) {
|
if (PyMethod_Check(func) && PyMethod_GET_SELF(func) == self) {
|
||||||
/* Deconstruct a bound Python method */
|
/* Deconstruct a bound Python method */
|
||||||
func2 = PyMethod_GET_FUNCTION(func);
|
|
||||||
Py_INCREF(func2);
|
|
||||||
*method_self = self; /* borrowed */
|
*method_self = self; /* borrowed */
|
||||||
Py_XSETREF(*method_func, func2);
|
func2 = PyMethod_GET_FUNCTION(func);
|
||||||
|
Py_XSETREF(*method_func, Py_NewRef(func2));
|
||||||
Py_DECREF(func);
|
Py_DECREF(func);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -408,8 +407,7 @@ reconstruct_method(PyObject *func, PyObject *self)
|
||||||
return PyMethod_New(func, self);
|
return PyMethod_New(func, self);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Py_INCREF(func);
|
return Py_NewRef(func);
|
||||||
return func;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -907,8 +905,7 @@ PyMemoTable_Set(PyMemoTable *self, PyObject *key, Py_ssize_t value)
|
||||||
entry->me_value = value;
|
entry->me_value = value;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Py_INCREF(key);
|
entry->me_key = Py_NewRef(key);
|
||||||
entry->me_key = key;
|
|
||||||
entry->me_value = value;
|
entry->me_value = value;
|
||||||
self->mt_used++;
|
self->mt_used++;
|
||||||
|
|
||||||
|
@ -1196,8 +1193,7 @@ _Pickler_SetBufferCallback(PicklerObject *self, PyObject *buffer_callback)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_XINCREF(buffer_callback);
|
self->buffer_callback = Py_XNewRef(buffer_callback);
|
||||||
self->buffer_callback = buffer_callback;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1543,9 +1539,8 @@ _Unpickler_MemoPut(UnpicklerObject *self, size_t idx, PyObject *value)
|
||||||
return -1;
|
return -1;
|
||||||
assert(idx < self->memo_size);
|
assert(idx < self->memo_size);
|
||||||
}
|
}
|
||||||
Py_INCREF(value);
|
|
||||||
old_item = self->memo[idx];
|
old_item = self->memo[idx];
|
||||||
self->memo[idx] = value;
|
self->memo[idx] = Py_NewRef(value);
|
||||||
if (old_item != NULL) {
|
if (old_item != NULL) {
|
||||||
Py_DECREF(old_item);
|
Py_DECREF(old_item);
|
||||||
}
|
}
|
||||||
|
@ -1928,8 +1923,7 @@ whichmodule(PyObject *global, PyObject *dotted_path)
|
||||||
i = 0;
|
i = 0;
|
||||||
while (PyDict_Next(modules, &i, &module_name, &module)) {
|
while (PyDict_Next(modules, &i, &module_name, &module)) {
|
||||||
if (_checkmodule(module_name, module, global, dotted_path) == 0) {
|
if (_checkmodule(module_name, module, global, dotted_path) == 0) {
|
||||||
Py_INCREF(module_name);
|
return Py_NewRef(module_name);
|
||||||
return module_name;
|
|
||||||
}
|
}
|
||||||
if (PyErr_Occurred()) {
|
if (PyErr_Occurred()) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1965,8 +1959,7 @@ whichmodule(PyObject *global, PyObject *dotted_path)
|
||||||
|
|
||||||
/* If no module is found, use __main__. */
|
/* If no module is found, use __main__. */
|
||||||
module_name = &_Py_ID(__main__);
|
module_name = &_Py_ID(__main__);
|
||||||
Py_INCREF(module_name);
|
return Py_NewRef(module_name);
|
||||||
return module_name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fast_save_enter() and fast_save_leave() are guards against recursive
|
/* fast_save_enter() and fast_save_leave() are guards against recursive
|
||||||
|
@ -3557,10 +3550,8 @@ fix_imports(PyObject **module_name, PyObject **global_name)
|
||||||
|
|
||||||
Py_CLEAR(*module_name);
|
Py_CLEAR(*module_name);
|
||||||
Py_CLEAR(*global_name);
|
Py_CLEAR(*global_name);
|
||||||
Py_INCREF(fixed_module_name);
|
*module_name = Py_NewRef(fixed_module_name);
|
||||||
Py_INCREF(fixed_global_name);
|
*global_name = Py_NewRef(fixed_global_name);
|
||||||
*module_name = fixed_module_name;
|
|
||||||
*global_name = fixed_global_name;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if (PyErr_Occurred()) {
|
else if (PyErr_Occurred()) {
|
||||||
|
@ -3576,8 +3567,7 @@ fix_imports(PyObject **module_name, PyObject **global_name)
|
||||||
Py_TYPE(item)->tp_name);
|
Py_TYPE(item)->tp_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
Py_INCREF(item);
|
Py_XSETREF(*module_name, Py_NewRef(item));
|
||||||
Py_XSETREF(*module_name, item);
|
|
||||||
}
|
}
|
||||||
else if (PyErr_Occurred()) {
|
else if (PyErr_Occurred()) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -3602,8 +3592,7 @@ save_global(PicklerObject *self, PyObject *obj, PyObject *name)
|
||||||
const char global_op = GLOBAL;
|
const char global_op = GLOBAL;
|
||||||
|
|
||||||
if (name) {
|
if (name) {
|
||||||
Py_INCREF(name);
|
global_name = Py_NewRef(name);
|
||||||
global_name = name;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (_PyObject_LookupAttr(obj, &_Py_ID(__qualname__), &global_name) < 0)
|
if (_PyObject_LookupAttr(obj, &_Py_ID(__qualname__), &global_name) < 0)
|
||||||
|
@ -3637,8 +3626,8 @@ save_global(PicklerObject *self, PyObject *obj, PyObject *name)
|
||||||
obj, module_name);
|
obj, module_name);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
lastname = PyList_GET_ITEM(dotted_path, PyList_GET_SIZE(dotted_path)-1);
|
lastname = Py_NewRef(PyList_GET_ITEM(dotted_path,
|
||||||
Py_INCREF(lastname);
|
PyList_GET_SIZE(dotted_path) - 1));
|
||||||
cls = get_deep_attribute(module, dotted_path, &parent);
|
cls = get_deep_attribute(module, dotted_path, &parent);
|
||||||
Py_CLEAR(dotted_path);
|
Py_CLEAR(dotted_path);
|
||||||
if (cls == NULL) {
|
if (cls == NULL) {
|
||||||
|
@ -3932,8 +3921,7 @@ get_class(PyObject *obj)
|
||||||
PyObject *cls;
|
PyObject *cls;
|
||||||
|
|
||||||
if (_PyObject_LookupAttr(obj, &_Py_ID(__class__), &cls) == 0) {
|
if (_PyObject_LookupAttr(obj, &_Py_ID(__class__), &cls) == 0) {
|
||||||
cls = (PyObject *) Py_TYPE(obj);
|
cls = Py_NewRef(Py_TYPE(obj));
|
||||||
Py_INCREF(cls);
|
|
||||||
}
|
}
|
||||||
return cls;
|
return cls;
|
||||||
}
|
}
|
||||||
|
@ -4084,12 +4072,10 @@ save_reduce(PicklerObject *self, PyObject *args, PyObject *obj)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
PyTuple_SET_ITEM(newargs, 0, cls_new);
|
PyTuple_SET_ITEM(newargs, 0, cls_new);
|
||||||
Py_INCREF(cls);
|
PyTuple_SET_ITEM(newargs, 1, Py_NewRef(cls));
|
||||||
PyTuple_SET_ITEM(newargs, 1, cls);
|
|
||||||
for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
|
for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
|
||||||
PyObject *item = PyTuple_GET_ITEM(args, i);
|
PyObject *item = PyTuple_GET_ITEM(args, i);
|
||||||
Py_INCREF(item);
|
PyTuple_SET_ITEM(newargs, i + 2, Py_NewRef(item));
|
||||||
PyTuple_SET_ITEM(newargs, i + 2, item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
callable = PyObject_Call(st->partial, newargs, kwargs);
|
callable = PyObject_Call(st->partial, newargs, kwargs);
|
||||||
|
@ -4405,8 +4391,7 @@ save(PicklerObject *self, PyObject *obj, int pers_save)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (reduce_func != NULL) {
|
if (reduce_func != NULL) {
|
||||||
Py_INCREF(obj);
|
reduce_value = _Pickle_FastCall(reduce_func, Py_NewRef(obj));
|
||||||
reduce_value = _Pickle_FastCall(reduce_func, obj);
|
|
||||||
}
|
}
|
||||||
else if (PyType_IsSubtype(type, &PyType_Type)) {
|
else if (PyType_IsSubtype(type, &PyType_Type)) {
|
||||||
status = save_global(self, obj, NULL);
|
status = save_global(self, obj, NULL);
|
||||||
|
@ -4869,8 +4854,7 @@ _pickle_PicklerMemoProxy___reduce___impl(PicklerMemoProxyObject *self)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
PyTuple_SET_ITEM(dict_args, 0, contents);
|
PyTuple_SET_ITEM(dict_args, 0, contents);
|
||||||
Py_INCREF((PyObject *)&PyDict_Type);
|
PyTuple_SET_ITEM(reduce_value, 0, Py_NewRef(&PyDict_Type));
|
||||||
PyTuple_SET_ITEM(reduce_value, 0, (PyObject *)&PyDict_Type);
|
|
||||||
PyTuple_SET_ITEM(reduce_value, 1, dict_args);
|
PyTuple_SET_ITEM(reduce_value, 1, dict_args);
|
||||||
return reduce_value;
|
return reduce_value;
|
||||||
}
|
}
|
||||||
|
@ -4944,8 +4928,7 @@ PicklerMemoProxy_New(PicklerObject *pickler)
|
||||||
self = PyObject_GC_New(PicklerMemoProxyObject, &PicklerMemoProxyType);
|
self = PyObject_GC_New(PicklerMemoProxyObject, &PicklerMemoProxyType);
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
Py_INCREF(pickler);
|
self->pickler = (PicklerObject*)Py_NewRef(pickler);
|
||||||
self->pickler = pickler;
|
|
||||||
PyObject_GC_Track(self);
|
PyObject_GC_Track(self);
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
}
|
}
|
||||||
|
@ -5045,8 +5028,7 @@ Pickler_set_persid(PicklerObject *self, PyObject *value, void *Py_UNUSED(ignored
|
||||||
}
|
}
|
||||||
|
|
||||||
self->pers_func_self = NULL;
|
self->pers_func_self = NULL;
|
||||||
Py_INCREF(value);
|
Py_XSETREF(self->pers_func, Py_NewRef(value));
|
||||||
Py_XSETREF(self->pers_func, value);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -7370,8 +7352,7 @@ _pickle_UnpicklerMemoProxy___reduce___impl(UnpicklerMemoProxyObject *self)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
PyTuple_SET_ITEM(constructor_args, 0, contents);
|
PyTuple_SET_ITEM(constructor_args, 0, contents);
|
||||||
Py_INCREF((PyObject *)&PyDict_Type);
|
PyTuple_SET_ITEM(reduce_value, 0, Py_NewRef(&PyDict_Type));
|
||||||
PyTuple_SET_ITEM(reduce_value, 0, (PyObject *)&PyDict_Type);
|
|
||||||
PyTuple_SET_ITEM(reduce_value, 1, constructor_args);
|
PyTuple_SET_ITEM(reduce_value, 1, constructor_args);
|
||||||
return reduce_value;
|
return reduce_value;
|
||||||
}
|
}
|
||||||
|
@ -7446,8 +7427,7 @@ UnpicklerMemoProxy_New(UnpicklerObject *unpickler)
|
||||||
&UnpicklerMemoProxyType);
|
&UnpicklerMemoProxyType);
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
Py_INCREF(unpickler);
|
self->unpickler = (UnpicklerObject*)Py_NewRef(unpickler);
|
||||||
self->unpickler = unpickler;
|
|
||||||
PyObject_GC_Track(self);
|
PyObject_GC_Track(self);
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
}
|
}
|
||||||
|
@ -7483,8 +7463,7 @@ Unpickler_set_memo(UnpicklerObject *self, PyObject *obj, void *Py_UNUSED(ignored
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (size_t i = 0; i < new_memo_size; i++) {
|
for (size_t i = 0; i < new_memo_size; i++) {
|
||||||
Py_XINCREF(unpickler->memo[i]);
|
new_memo[i] = Py_XNewRef(unpickler->memo[i]);
|
||||||
new_memo[i] = unpickler->memo[i];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (PyDict_Check(obj)) {
|
else if (PyDict_Check(obj)) {
|
||||||
|
@ -7564,8 +7543,7 @@ Unpickler_set_persload(UnpicklerObject *self, PyObject *value, void *Py_UNUSED(i
|
||||||
}
|
}
|
||||||
|
|
||||||
self->pers_func_self = NULL;
|
self->pers_func_self = NULL;
|
||||||
Py_INCREF(value);
|
Py_XSETREF(self->pers_func, Py_NewRef(value));
|
||||||
Py_XSETREF(self->pers_func, value);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -7944,8 +7922,7 @@ PyInit__pickle(void)
|
||||||
|
|
||||||
m = PyState_FindModule(&_picklemodule);
|
m = PyState_FindModule(&_picklemodule);
|
||||||
if (m) {
|
if (m) {
|
||||||
Py_INCREF(m);
|
return Py_NewRef(m);
|
||||||
return m;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PyType_Ready(&Pdata_Type) < 0)
|
if (PyType_Ready(&Pdata_Type) < 0)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue