if (st == NULL) {
return NULL;
}
- t = (PyObject *)st->st_top;
- Py_INCREF(t);
+ t = Py_NewRef(st->st_top);
_PySymtable_Free(st);
return t;
}
return NULL;
}
else {
- Py_INCREF(default_value);
- return default_value;
+ return Py_NewRef(default_value);
}
}
return PyLong_FromLong(rc);
return NULL;
}
else {
- Py_INCREF(default_value);
- return default_value;
+ return Py_NewRef(default_value);
}
}
return PyLong_FromLong(rc);
return NULL;
}
else {
- Py_INCREF(default_value);
- return default_value;
+ return Py_NewRef(default_value);
}
}
return PyFloat_FromDouble(rc);
result = (m == YES) ? Py_True : Py_False;
}
- Py_INCREF(result);
- return result;
+ return Py_NewRef(result);
}
if (PyUnicode_GET_LENGTH(input) == 0) {
/* Special case empty input strings, since resizing
them later would cause internal errors. */
- Py_INCREF(input);
- return input;
+ return Py_NewRef(input);
}
if (PyUnicode_CompareWithASCIIString(form, "NFC") == 0) {
if (is_normalized_quickcheck(self, input,
true, false, true) == YES) {
- Py_INCREF(input);
- return input;
+ return Py_NewRef(input);
}
return nfc_nfkc(self, input, 0);
}
if (PyUnicode_CompareWithASCIIString(form, "NFKC") == 0) {
if (is_normalized_quickcheck(self, input,
true, true, true) == YES) {
- Py_INCREF(input);
- return input;
+ return Py_NewRef(input);
}
return nfc_nfkc(self, input, 1);
}
if (PyUnicode_CompareWithASCIIString(form, "NFD") == 0) {
if (is_normalized_quickcheck(self, input,
false, false, true) == YES) {
- Py_INCREF(input);
- return input;
+ return Py_NewRef(input);
}
return nfd_nfkd(self, input, 0);
}
if (PyUnicode_CompareWithASCIIString(form, "NFKD") == 0) {
if (is_normalized_quickcheck(self, input,
false, true, true) == YES) {
- Py_INCREF(input);
- return input;
+ return Py_NewRef(input);
}
return nfd_nfkd(self, input, 1);
}
return NULL;
}
else {
- Py_INCREF(default_value);
- return default_value;
+ return Py_NewRef(default_value);
}
}
if (self->x_attr != NULL) {
PyObject *v = PyDict_GetItemWithError(self->x_attr, name);
if (v != NULL) {
- Py_INCREF(v);
- return v;
+ return Py_NewRef(v);
}
else if (PyErr_Occurred()) {
return NULL;
/* Test if the argument is "str" */
if (PyUnicode_Check(o)) {
- Py_INCREF(o);
- return o;
+ return Py_NewRef(o);
}
/* test if the argument is of the Xxo class */
if (PyObject_TypeCheck(o, defining_class)) {
- Py_INCREF(o);
- return o;
+ return Py_NewRef(o);
}
- Py_INCREF(Py_None);
- return Py_None;
+ return Py_NewRef(Py_None);
}
static PyMethodDef Xxo_methods[] = {
return NULL;
/* Test availability of fast type checks */
if (o != NULL && PyUnicode_Check(o)) {
- Py_INCREF(o);
- return o;
+ return Py_NewRef(o);
}
- Py_INCREF(Py_None);
- return Py_None;
+ return Py_NewRef(Py_None);
}
static PyMethodDef Xxo_methods[] = {
if (self->x_attr != NULL) {
PyObject *v = PyDict_GetItemWithError(self->x_attr, name);
if (v != NULL) {
- Py_INCREF(v);
- return v;
+ return Py_NewRef(v);
}
else if (PyErr_Occurred()) {
return NULL;
long b;
if (!PyArg_ParseTuple(args, "O#:roj", &a, &b))
return NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ return Py_NewRef(Py_None);
}
{
if (!PyArg_ParseTuple(args, ":demo"))
return NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ return Py_NewRef(Py_None);
}
static PyMethodDef Xxo_methods[] = {
if (self->x_attr != NULL) {
PyObject *v = PyDict_GetItemWithError(self->x_attr, name);
if (v != NULL) {
- Py_INCREF(v);
- return v;
+ return Py_NewRef(v);
}
else if (PyErr_Occurred()) {
return NULL;
printf("\n");
/* Py_DECREF(item); */
- Py_INCREF(Py_None);
- return Py_None;
+ return Py_NewRef(Py_None);
}
/* Test bad format character */
long b;
if (!PyArg_ParseTuple(args, "O#:roj", &a, &b))
return NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ return Py_NewRef(Py_None);
}
static PyObject *
null_richcompare(PyObject *self, PyObject *other, int op)
{
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
+ return Py_NewRef(Py_NotImplemented);
}
static PyTypeObject Null_Type = {
if (!PyArg_ParseTuple(args, "i:setstate", &state))
return NULL;
self->state = state;
- Py_INCREF(Py_None);
- return Py_None;
+ return Py_NewRef(Py_None);
}
static PyObject *
self = Py_None;
if (kw == NULL)
kw = Py_None;
- Py_INCREF(self);
- PyTuple_SET_ITEM(result, 0, self);
- Py_INCREF(args);
- PyTuple_SET_ITEM(result, 1, args);
- Py_INCREF(kw);
- PyTuple_SET_ITEM(result, 2, kw);
+ PyTuple_SET_ITEM(result, 0, Py_NewRef(self));
+ PyTuple_SET_ITEM(result, 1, Py_NewRef(args));
+ PyTuple_SET_ITEM(result, 2, Py_NewRef(kw));
}
return result;
}
if (!PyArg_ParseTuple(args, "i:setstate", &state))
return NULL;
self->state = state;
- Py_INCREF(Py_None);
- return Py_None;
+ return Py_NewRef(Py_None);
}
static PyMethodDef spamdict_methods[] = {
if (PyType_Ready(&spamdict_type) < 0)
return -1;
- Py_INCREF(&spamlist_type);
if (PyModule_AddObject(m, "spamlist",
- (PyObject *) &spamlist_type) < 0)
+ Py_NewRef(&spamlist_type)) < 0)
return -1;
- Py_INCREF(&spamdict_type);
if (PyModule_AddObject(m, "spamdict",
- (PyObject *) &spamdict_type) < 0)
+ Py_NewRef(&spamdict_type)) < 0)
return -1;
return 0;
}
self->zst.next_in = NULL;
self->zst.avail_in = 0;
if (zdict != NULL) {
- Py_INCREF(zdict);
- self->zdict = zdict;
+ self->zdict = Py_NewRef(zdict);
}
int err = inflateInit2(&self->zst, wbits);
switch (err) {
zlib_error(state, self->zst, err, "while copying compression object");
goto error;
}
- Py_INCREF(self->unused_data);
- Py_XSETREF(return_value->unused_data, self->unused_data);
- Py_INCREF(self->unconsumed_tail);
- Py_XSETREF(return_value->unconsumed_tail, self->unconsumed_tail);
- Py_XINCREF(self->zdict);
- Py_XSETREF(return_value->zdict, self->zdict);
+ Py_XSETREF(return_value->unused_data, Py_NewRef(self->unused_data));
+ Py_XSETREF(return_value->unconsumed_tail, Py_NewRef(self->unconsumed_tail));
+ Py_XSETREF(return_value->zdict, Py_XNewRef(self->zdict));
return_value->eof = self->eof;
/* Mark it as being initialized */
goto error;
}
- Py_INCREF(self->unused_data);
- Py_XSETREF(return_value->unused_data, self->unused_data);
- Py_INCREF(self->unconsumed_tail);
- Py_XSETREF(return_value->unconsumed_tail, self->unconsumed_tail);
- Py_XINCREF(self->zdict);
- Py_XSETREF(return_value->zdict, self->zdict);
+ Py_XSETREF(return_value->unused_data, Py_NewRef(self->unused_data));
+ Py_XSETREF(return_value->unconsumed_tail, Py_NewRef(self->unconsumed_tail));
+ Py_XSETREF(return_value->zdict, Py_XNewRef(self->zdict));
return_value->eof = self->eof;
/* Mark it as being initialized */
return length;
}
-/* Decompress data of length self->avail_in_real in self->state.next_in. The
- output buffer is allocated dynamically and returned. If the max_length is
- of sufficiently low size, max_length is allocated immediately. At most
- max_length bytes are returned, so some of the input may not be consumed.
- self->state.next_in and self->avail_in_real are updated to reflect the
+/* Decompress data of length self->avail_in_real in self->state.next_in. The
+ output buffer is allocated dynamically and returned. If the max_length is
+ of sufficiently low size, max_length is allocated immediately. At most
+ max_length bytes are returned, so some of the input may not be consumed.
+ self->state.next_in and self->avail_in_real are updated to reflect the
consumed input. */
static PyObject*
decompress_buf(ZlibDecompressor *self, Py_ssize_t max_length)
Py_ssize_t hard_limit;
Py_ssize_t obuflen;
zlibstate *state = PyType_GetModuleState(Py_TYPE(self));
-
+
int err = Z_OK;
- /* When sys.maxsize is passed as default use DEF_BUF_SIZE as start buffer.
- In this particular case the data may not necessarily be very big, so
+ /* When sys.maxsize is passed as default use DEF_BUF_SIZE as start buffer.
+ In this particular case the data may not necessarily be very big, so
it is better to grow dynamically.*/
if ((max_length < 0) || max_length == PY_SSIZE_T_MAX) {
hard_limit = PY_SSIZE_T_MAX;
static PyObject *
-decompress(ZlibDecompressor *self, uint8_t *data,
+decompress(ZlibDecompressor *self, uint8_t *data,
size_t len, Py_ssize_t max_length)
{
bool input_buffer_in_use;
"\n");
static PyObject *
-ZlibDecompressor__new__(PyTypeObject *cls,
- PyObject *args,
+ZlibDecompressor__new__(PyTypeObject *cls,
+ PyObject *args,
PyObject *kwargs)
{
static char *keywords[] = {"wbits", "zdict", NULL};
args, kwargs, format, keywords, &wbits, &zdict)) {
return NULL;
}
- ZlibDecompressor *self = PyObject_New(ZlibDecompressor, cls);
+ ZlibDecompressor *self = PyObject_New(ZlibDecompressor, cls);
self->eof = 0;
self->needs_input = 1;
self->avail_in_real = 0;
self->input_buffer = NULL;
self->input_buffer_size = 0;
- if (zdict != NULL) {
- Py_INCREF(zdict);
- }
- self->zdict = zdict;
+ self->zdict = Py_XNewRef(zdict);
self->zst.opaque = NULL;
self->zst.zalloc = PyZlib_Malloc;
self->zst.zfree = PyZlib_Free;
return -1;
}
- Py_INCREF(state->ZlibError);
- if (PyModule_AddObject(mod, "error", state->ZlibError) < 0) {
+ if (PyModule_AddObject(mod, "error", Py_NewRef(state->ZlibError)) < 0) {
Py_DECREF(state->ZlibError);
return -1;
}
- Py_INCREF(state->ZlibDecompressorType);
- if (PyModule_AddObject(mod, "_ZlibDecompressor",
- (PyObject *)state->ZlibDecompressorType) < 0) {
+ if (PyModule_AddObject(mod, "_ZlibDecompressor",
+ Py_NewRef(state->ZlibDecompressorType)) < 0) {
Py_DECREF(state->ZlibDecompressorType);
return -1;
}