diff --git a/psycopg/adapter_binary.c b/psycopg/adapter_binary.c index 54f0f656..3edcea8d 100644 --- a/psycopg/adapter_binary.c +++ b/psycopg/adapter_binary.c @@ -159,8 +159,7 @@ binary_prepare(binaryObject *self, PyObject *args) self->conn = conn; Py_INCREF(self->conn); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * diff --git a/psycopg/adapter_list.c b/psycopg/adapter_list.c index 7e2b7e3b..1198a81b 100644 --- a/psycopg/adapter_list.c +++ b/psycopg/adapter_list.c @@ -107,8 +107,7 @@ list_prepare(listObject *self, PyObject *args) Py_INCREF(conn); self->connection = conn; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * diff --git a/psycopg/adapter_qstring.c b/psycopg/adapter_qstring.c index 6728017e..91c14673 100644 --- a/psycopg/adapter_qstring.c +++ b/psycopg/adapter_qstring.c @@ -128,8 +128,7 @@ qstring_prepare(qstringObject *self, PyObject *args) Py_INCREF(conn); self->conn = conn; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * diff --git a/psycopg/connection_type.c b/psycopg/connection_type.c index 79d11aa1..89dd635e 100644 --- a/psycopg/connection_type.c +++ b/psycopg/connection_type.c @@ -130,8 +130,7 @@ psyco_conn_close(connectionObject *self) conn_close(self); Dprintf("psyco_conn_close: connection at %p closed", self); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } @@ -149,8 +148,7 @@ psyco_conn_commit(connectionObject *self) if (conn_commit(self) < 0) return NULL; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } @@ -169,8 +167,7 @@ psyco_conn_rollback(connectionObject *self) if (conn_rollback(self) < 0) return NULL; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } @@ -254,8 +251,7 @@ psyco_conn_tpc_prepare(connectionObject *self) * can be performed until commit. */ self->status = CONN_STATUS_PREPARED; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } @@ -583,8 +579,7 @@ psyco_conn_set_session(connectionObject *self, PyObject *args, PyObject *kwargs) return NULL; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } @@ -666,8 +661,7 @@ psyco_conn_set_isolation_level(connectionObject *self, PyObject *args) return NULL; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } /* set_client_encoding method - set client encoding */ @@ -730,8 +724,7 @@ psyco_conn_get_parameter_status(connectionObject *self, PyObject *args) val = PQparameterStatus(self->pgconn, param); if (!val) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } return conn_text_from_chars(self, val); } @@ -831,8 +824,7 @@ psyco_conn_reset(connectionObject *self) if (res < 0) return NULL; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } static PyObject * @@ -939,8 +931,7 @@ psyco_conn_cancel(connectionObject *self) PyErr_SetString(OperationalError, errbuf); return NULL; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } #endif /* PSYCOPG_EXTENSIONS */ diff --git a/psycopg/cursor_type.c b/psycopg/cursor_type.c index 831425ab..7cf60dec 100644 --- a/psycopg/cursor_type.c +++ b/psycopg/cursor_type.c @@ -70,8 +70,7 @@ psyco_curs_close(cursorObject *self) Dprintf("psyco_curs_close: cursor at %p closed", self); exit: - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } @@ -496,8 +495,7 @@ psyco_curs_execute(cursorObject *self, PyObject *args, PyObject *kwargs) } /* success */ - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } #define psyco_curs_executemany_doc \ @@ -553,8 +551,7 @@ psyco_curs_executemany(cursorObject *self, PyObject *args, PyObject *kwargs) self->rowcount = rowcount; if (!PyErr_Occurred()) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } else { return NULL; @@ -778,8 +775,7 @@ psyco_curs_fetchone(cursorObject *self) if (self->row >= self->rowcount) { /* we exausted available data: return None */ - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } res = _psyco_curs_buildrow(self, self->row); @@ -1103,8 +1099,7 @@ psyco_curs_setinputsizes(cursorObject *self, PyObject *args) EXC_IF_CURS_CLOSED(self); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } @@ -1124,8 +1119,7 @@ psyco_curs_setoutputsize(cursorObject *self, PyObject *args) EXC_IF_CURS_CLOSED(self); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } @@ -1189,8 +1183,7 @@ psyco_curs_scroll(cursorObject *self, PyObject *args, PyObject *kwargs) if (_psyco_curs_prefetch(self) < 0) return NULL; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } diff --git a/psycopg/diagnostics_type.c b/psycopg/diagnostics_type.c index c9f8a57a..dbcbf38e 100644 --- a/psycopg/diagnostics_type.c +++ b/psycopg/diagnostics_type.c @@ -58,8 +58,7 @@ psyco_diagnostics_get_field(diagnosticsObject *self, void *closure) const char *errortext; if (!self->err->pgres) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } errortext = PQresultErrorField(self->err->pgres, (Py_intptr_t) closure); diff --git a/psycopg/green.c b/psycopg/green.c index 3ffa810b..e7604076 100644 --- a/psycopg/green.c +++ b/psycopg/green.c @@ -53,8 +53,7 @@ psyco_set_wait_callback(PyObject *self, PyObject *obj) wait_callback = NULL; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } diff --git a/psycopg/lobject_type.c b/psycopg/lobject_type.c index 90546e79..5e9fbc14 100644 --- a/psycopg/lobject_type.c +++ b/psycopg/lobject_type.c @@ -59,8 +59,7 @@ psyco_lobj_close(lobjectObject *self, PyObject *args) return NULL; } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } /* write method - write data to the lobject */ @@ -213,10 +212,9 @@ static PyObject * psyco_lobj_unlink(lobjectObject *self, PyObject *args) { if (lobject_unlink(self) < 0) - return NULL; + return NULL; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } /* export method - export lobject's content to given file */ @@ -230,15 +228,14 @@ psyco_lobj_export(lobjectObject *self, PyObject *args) const char *filename; if (!PyArg_ParseTuple(args, "s", &filename)) - return NULL; + return NULL; EXC_IF_LOBJ_LEVEL0(self); if (lobject_export(self, filename) < 0) - return NULL; + return NULL; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } @@ -272,8 +269,7 @@ psyco_lobj_truncate(lobjectObject *self, PyObject *args) if (lobject_truncate(self, len) < 0) return NULL; - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } #endif /* PG_VERSION_HEX >= 0x080300 */ diff --git a/psycopg/microprotocols_proto.c b/psycopg/microprotocols_proto.c index 6065efdf..f30da3f4 100644 --- a/psycopg/microprotocols_proto.c +++ b/psycopg/microprotocols_proto.c @@ -42,8 +42,7 @@ static PyObject * psyco_isqlquote_getquoted(isqlquoteObject *self, PyObject *args) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } /* getbinary - return quoted representation for object */ @@ -54,8 +53,7 @@ psyco_isqlquote_getquoted(isqlquoteObject *self, PyObject *args) static PyObject * psyco_isqlquote_getbinary(isqlquoteObject *self, PyObject *args) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } /* getbuffer - return quoted representation for object */ @@ -66,8 +64,7 @@ psyco_isqlquote_getbinary(isqlquoteObject *self, PyObject *args) static PyObject * psyco_isqlquote_getbuffer(isqlquoteObject *self, PyObject *args) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c index 4f61d765..46f27dae 100644 --- a/psycopg/psycopgmodule.c +++ b/psycopg/psycopgmodule.c @@ -177,8 +177,7 @@ psyco_register_type(PyObject *self, PyObject *args) if (0 > typecast_add(type, NULL, 0)) { return NULL; } } - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } diff --git a/psycopg/typecast.c b/psycopg/typecast.c index ecaab0dd..9678a36b 100644 --- a/psycopg/typecast.c +++ b/psycopg/typecast.c @@ -474,8 +474,7 @@ typecast_call(PyObject *obj, PyObject *args, PyObject *kwargs) // If the string is not a string but a None value we're being called // from a Python-defined caster. if (!string) { - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } return typecast_cast(obj, string, length, cursor); diff --git a/psycopg/typecast_array.c b/psycopg/typecast_array.c index 21e2affc..adf07eee 100644 --- a/psycopg/typecast_array.c +++ b/psycopg/typecast_array.c @@ -253,7 +253,7 @@ typecast_GENERIC_ARRAY_cast(const char *str, Py_ssize_t len, PyObject *curs) Dprintf("typecast_GENERIC_ARRAY_cast: str = '%s'," " len = " FORMAT_CODE_PY_SSIZE_T, str, len); - if (str == NULL) {Py_INCREF(Py_None); return Py_None;} + if (str == NULL) { Py_RETURN_NONE; } if (str[0] == '[') typecast_array_cleanup(&str, &len); if (str[0] != '{') { diff --git a/psycopg/typecast_basic.c b/psycopg/typecast_basic.c index 5e2a93ea..a31047f3 100644 --- a/psycopg/typecast_basic.c +++ b/psycopg/typecast_basic.c @@ -31,7 +31,7 @@ typecast_INTEGER_cast(const char *s, Py_ssize_t len, PyObject *curs) { char buffer[12]; - if (s == NULL) {Py_INCREF(Py_None); return Py_None;} + if (s == NULL) { Py_RETURN_NONE; } if (s[len] != '\0') { strncpy(buffer, s, (size_t) len); buffer[len] = '\0'; s = buffer; @@ -49,7 +49,7 @@ typecast_LONGINTEGER_cast(const char *s, Py_ssize_t len, PyObject *curs) { char buffer[24]; - if (s == NULL) {Py_INCREF(Py_None); return Py_None;} + if (s == NULL) { Py_RETURN_NONE; } if (s[len] != '\0') { strncpy(buffer, s, (size_t) len); buffer[len] = '\0'; s = buffer; @@ -64,7 +64,7 @@ typecast_FLOAT_cast(const char *s, Py_ssize_t len, PyObject *curs) { PyObject *str = NULL, *flo = NULL; - if (s == NULL) {Py_INCREF(Py_None); return Py_None;} + if (s == NULL) { Py_RETURN_NONE; } if (!(str = Text_FromUTF8AndSize(s, len))) { return NULL; } #if PY_MAJOR_VERSION < 3 flo = PyFloat_FromString(str, NULL); @@ -81,7 +81,7 @@ typecast_FLOAT_cast(const char *s, Py_ssize_t len, PyObject *curs) static PyObject * typecast_STRING_cast(const char *s, Py_ssize_t len, PyObject *curs) { - if (s == NULL) {Py_INCREF(Py_None); return Py_None;} + if (s == NULL) { Py_RETURN_NONE; } return PyString_FromStringAndSize(s, len); } #else @@ -95,7 +95,7 @@ typecast_UNICODE_cast(const char *s, Py_ssize_t len, PyObject *curs) { char *enc; - if (s == NULL) {Py_INCREF(Py_None); return Py_None;} + if (s == NULL) { Py_RETURN_NONE; } enc = ((cursorObject*)curs)->conn->codec; return PyUnicode_Decode(s, len, enc, NULL); @@ -108,7 +108,7 @@ typecast_BOOLEAN_cast(const char *s, Py_ssize_t len, PyObject *curs) { PyObject *res; - if (s == NULL) {Py_INCREF(Py_None); return Py_None;} + if (s == NULL) { Py_RETURN_NONE; } if (s[0] == 't') res = Py_True; @@ -128,7 +128,7 @@ typecast_DECIMAL_cast(const char *s, Py_ssize_t len, PyObject *curs) PyObject *decimalType; char *buffer; - if (s == NULL) {Py_INCREF(Py_None); return Py_None;} + if (s == NULL) { Py_RETURN_NONE; } if ((buffer = PyMem_Malloc(len+1)) == NULL) return PyErr_NoMemory(); diff --git a/psycopg/typecast_binary.c b/psycopg/typecast_binary.c index 95bf3dc8..ce68fb8f 100644 --- a/psycopg/typecast_binary.c +++ b/psycopg/typecast_binary.c @@ -146,7 +146,7 @@ typecast_BINARY_cast(const char *s, Py_ssize_t l, PyObject *curs) char *buffer = NULL; Py_ssize_t len; - if (s == NULL) {Py_INCREF(Py_None); return Py_None;} + if (s == NULL) { Py_RETURN_NONE; } if (s[0] == '\\' && s[1] == 'x') { /* This is a buffer escaped in hex format: libpq before 9.0 can't diff --git a/psycopg/typecast_datetime.c b/psycopg/typecast_datetime.c index 18e9d0d8..ad74101a 100644 --- a/psycopg/typecast_datetime.c +++ b/psycopg/typecast_datetime.c @@ -48,7 +48,7 @@ typecast_PYDATE_cast(const char *str, Py_ssize_t len, PyObject *curs) PyObject* obj = NULL; int n, y=0, m=0, d=0; - if (str == NULL) {Py_INCREF(Py_None); return Py_None;} + if (str == NULL) { Py_RETURN_NONE; } if (!strcmp(str, "infinity") || !strcmp(str, "-infinity")) { if (str[0] == '-') { @@ -92,7 +92,7 @@ typecast_PYDATETIME_cast(const char *str, Py_ssize_t len, PyObject *curs) int hh=0, mm=0, ss=0, us=0, tz=0; const char *tp = NULL; - if (str == NULL) {Py_INCREF(Py_None); return Py_None;} + if (str == NULL) { Py_RETURN_NONE; } /* check for infinity */ if (!strcmp(str, "infinity") || !strcmp(str, "-infinity")) { @@ -177,7 +177,7 @@ typecast_PYTIME_cast(const char *str, Py_ssize_t len, PyObject *curs) PyObject *tzinfo_factory; int n, hh=0, mm=0, ss=0, us=0, tz=0; - if (str == NULL) {Py_INCREF(Py_None); return Py_None;} + if (str == NULL) { Py_RETURN_NONE; } n = typecast_parse_time(str, NULL, &len, &hh, &mm, &ss, &us, &tz); Dprintf("typecast_PYTIME_cast: n = %d, len = " FORMAT_CODE_PY_SSIZE_T ", " @@ -226,7 +226,7 @@ typecast_PYINTERVAL_cast(const char *str, Py_ssize_t len, PyObject *curs) int part = 0, sec; double micro; - if (str == NULL) {Py_INCREF(Py_None); return Py_None;} + if (str == NULL) { Py_RETURN_NONE; } Dprintf("typecast_PYINTERVAL_cast: s = %s", str); diff --git a/psycopg/typecast_mxdatetime.c b/psycopg/typecast_mxdatetime.c index bf69af5a..4b03d158 100644 --- a/psycopg/typecast_mxdatetime.c +++ b/psycopg/typecast_mxdatetime.c @@ -51,7 +51,7 @@ typecast_MXDATE_cast(const char *str, Py_ssize_t len, PyObject *curs) int hh=0, mm=0, ss=0, us=0, tz=0; const char *tp = NULL; - if (str == NULL) {Py_INCREF(Py_None); return Py_None;} + if (str == NULL) { Py_RETURN_NONE; } Dprintf("typecast_MXDATE_cast: s = %s", str); @@ -99,7 +99,7 @@ typecast_MXTIME_cast(const char *str, Py_ssize_t len, PyObject *curs) { int n, hh=0, mm=0, ss=0, us=0, tz=0; - if (str == NULL) {Py_INCREF(Py_None); return Py_None;} + if (str == NULL) { Py_RETURN_NONE; } Dprintf("typecast_MXTIME_cast: s = %s", str); @@ -129,7 +129,7 @@ typecast_MXINTERVAL_cast(const char *str, Py_ssize_t len, PyObject *curs) double v = 0.0, sign = 1.0; int part = 0; - if (str == NULL) {Py_INCREF(Py_None); return Py_None;} + if (str == NULL) { Py_RETURN_NONE; } Dprintf("typecast_MXINTERVAL_cast: s = %s", str);