Use the Py_RETURN_NONE macro

This commit is contained in:
Daniele Varrazzo 2013-04-05 01:25:05 +01:00
parent 67c8250081
commit beea32ef03
16 changed files with 49 additions and 79 deletions

View File

@ -159,8 +159,7 @@ binary_prepare(binaryObject *self, PyObject *args)
self->conn = conn; self->conn = conn;
Py_INCREF(self->conn); Py_INCREF(self->conn);
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }
static PyObject * static PyObject *

View File

@ -107,8 +107,7 @@ list_prepare(listObject *self, PyObject *args)
Py_INCREF(conn); Py_INCREF(conn);
self->connection = conn; self->connection = conn;
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }
static PyObject * static PyObject *

View File

@ -128,8 +128,7 @@ qstring_prepare(qstringObject *self, PyObject *args)
Py_INCREF(conn); Py_INCREF(conn);
self->conn = conn; self->conn = conn;
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }
static PyObject * static PyObject *

View File

@ -130,8 +130,7 @@ psyco_conn_close(connectionObject *self)
conn_close(self); conn_close(self);
Dprintf("psyco_conn_close: connection at %p closed", self); Dprintf("psyco_conn_close: connection at %p closed", self);
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }
@ -149,8 +148,7 @@ psyco_conn_commit(connectionObject *self)
if (conn_commit(self) < 0) if (conn_commit(self) < 0)
return NULL; return NULL;
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }
@ -169,8 +167,7 @@ psyco_conn_rollback(connectionObject *self)
if (conn_rollback(self) < 0) if (conn_rollback(self) < 0)
return NULL; return NULL;
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }
@ -254,8 +251,7 @@ psyco_conn_tpc_prepare(connectionObject *self)
* can be performed until commit. */ * can be performed until commit. */
self->status = CONN_STATUS_PREPARED; self->status = CONN_STATUS_PREPARED;
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }
@ -583,8 +579,7 @@ psyco_conn_set_session(connectionObject *self, PyObject *args, PyObject *kwargs)
return NULL; return NULL;
} }
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }
@ -666,8 +661,7 @@ psyco_conn_set_isolation_level(connectionObject *self, PyObject *args)
return NULL; return NULL;
} }
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }
/* set_client_encoding method - set client encoding */ /* 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); val = PQparameterStatus(self->pgconn, param);
if (!val) { if (!val) {
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }
return conn_text_from_chars(self, val); return conn_text_from_chars(self, val);
} }
@ -831,8 +824,7 @@ psyco_conn_reset(connectionObject *self)
if (res < 0) if (res < 0)
return NULL; return NULL;
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }
static PyObject * static PyObject *
@ -939,8 +931,7 @@ psyco_conn_cancel(connectionObject *self)
PyErr_SetString(OperationalError, errbuf); PyErr_SetString(OperationalError, errbuf);
return NULL; return NULL;
} }
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }
#endif /* PSYCOPG_EXTENSIONS */ #endif /* PSYCOPG_EXTENSIONS */

View File

@ -70,8 +70,7 @@ psyco_curs_close(cursorObject *self)
Dprintf("psyco_curs_close: cursor at %p closed", self); Dprintf("psyco_curs_close: cursor at %p closed", self);
exit: exit:
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }
@ -496,8 +495,7 @@ psyco_curs_execute(cursorObject *self, PyObject *args, PyObject *kwargs)
} }
/* success */ /* success */
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }
#define psyco_curs_executemany_doc \ #define psyco_curs_executemany_doc \
@ -553,8 +551,7 @@ psyco_curs_executemany(cursorObject *self, PyObject *args, PyObject *kwargs)
self->rowcount = rowcount; self->rowcount = rowcount;
if (!PyErr_Occurred()) { if (!PyErr_Occurred()) {
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }
else { else {
return NULL; return NULL;
@ -778,8 +775,7 @@ psyco_curs_fetchone(cursorObject *self)
if (self->row >= self->rowcount) { if (self->row >= self->rowcount) {
/* we exausted available data: return None */ /* we exausted available data: return None */
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }
res = _psyco_curs_buildrow(self, self->row); res = _psyco_curs_buildrow(self, self->row);
@ -1103,8 +1099,7 @@ psyco_curs_setinputsizes(cursorObject *self, PyObject *args)
EXC_IF_CURS_CLOSED(self); EXC_IF_CURS_CLOSED(self);
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }
@ -1124,8 +1119,7 @@ psyco_curs_setoutputsize(cursorObject *self, PyObject *args)
EXC_IF_CURS_CLOSED(self); EXC_IF_CURS_CLOSED(self);
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }
@ -1189,8 +1183,7 @@ psyco_curs_scroll(cursorObject *self, PyObject *args, PyObject *kwargs)
if (_psyco_curs_prefetch(self) < 0) return NULL; if (_psyco_curs_prefetch(self) < 0) return NULL;
} }
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }

View File

@ -58,8 +58,7 @@ psyco_diagnostics_get_field(diagnosticsObject *self, void *closure)
const char *errortext; const char *errortext;
if (!self->err->pgres) { if (!self->err->pgres) {
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }
errortext = PQresultErrorField(self->err->pgres, (Py_intptr_t) closure); errortext = PQresultErrorField(self->err->pgres, (Py_intptr_t) closure);

View File

@ -53,8 +53,7 @@ psyco_set_wait_callback(PyObject *self, PyObject *obj)
wait_callback = NULL; wait_callback = NULL;
} }
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }

View File

@ -59,8 +59,7 @@ psyco_lobj_close(lobjectObject *self, PyObject *args)
return NULL; return NULL;
} }
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }
/* write method - write data to the lobject */ /* write method - write data to the lobject */
@ -213,10 +212,9 @@ static PyObject *
psyco_lobj_unlink(lobjectObject *self, PyObject *args) psyco_lobj_unlink(lobjectObject *self, PyObject *args)
{ {
if (lobject_unlink(self) < 0) if (lobject_unlink(self) < 0)
return NULL; return NULL;
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }
/* export method - export lobject's content to given file */ /* export method - export lobject's content to given file */
@ -230,15 +228,14 @@ psyco_lobj_export(lobjectObject *self, PyObject *args)
const char *filename; const char *filename;
if (!PyArg_ParseTuple(args, "s", &filename)) if (!PyArg_ParseTuple(args, "s", &filename))
return NULL; return NULL;
EXC_IF_LOBJ_LEVEL0(self); EXC_IF_LOBJ_LEVEL0(self);
if (lobject_export(self, filename) < 0) if (lobject_export(self, filename) < 0)
return NULL; return NULL;
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }
@ -272,8 +269,7 @@ psyco_lobj_truncate(lobjectObject *self, PyObject *args)
if (lobject_truncate(self, len) < 0) if (lobject_truncate(self, len) < 0)
return NULL; return NULL;
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }
#endif /* PG_VERSION_HEX >= 0x080300 */ #endif /* PG_VERSION_HEX >= 0x080300 */

View File

@ -42,8 +42,7 @@
static PyObject * static PyObject *
psyco_isqlquote_getquoted(isqlquoteObject *self, PyObject *args) psyco_isqlquote_getquoted(isqlquoteObject *self, PyObject *args)
{ {
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }
/* getbinary - return quoted representation for object */ /* getbinary - return quoted representation for object */
@ -54,8 +53,7 @@ psyco_isqlquote_getquoted(isqlquoteObject *self, PyObject *args)
static PyObject * static PyObject *
psyco_isqlquote_getbinary(isqlquoteObject *self, PyObject *args) psyco_isqlquote_getbinary(isqlquoteObject *self, PyObject *args)
{ {
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }
/* getbuffer - return quoted representation for object */ /* getbuffer - return quoted representation for object */
@ -66,8 +64,7 @@ psyco_isqlquote_getbinary(isqlquoteObject *self, PyObject *args)
static PyObject * static PyObject *
psyco_isqlquote_getbuffer(isqlquoteObject *self, PyObject *args) psyco_isqlquote_getbuffer(isqlquoteObject *self, PyObject *args)
{ {
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }

View File

@ -177,8 +177,7 @@ psyco_register_type(PyObject *self, PyObject *args)
if (0 > typecast_add(type, NULL, 0)) { return NULL; } if (0 > typecast_add(type, NULL, 0)) { return NULL; }
} }
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }

View File

@ -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 // If the string is not a string but a None value we're being called
// from a Python-defined caster. // from a Python-defined caster.
if (!string) { if (!string) {
Py_INCREF(Py_None); Py_RETURN_NONE;
return Py_None;
} }
return typecast_cast(obj, string, length, cursor); return typecast_cast(obj, string, length, cursor);

View File

@ -253,7 +253,7 @@ typecast_GENERIC_ARRAY_cast(const char *str, Py_ssize_t len, PyObject *curs)
Dprintf("typecast_GENERIC_ARRAY_cast: str = '%s'," Dprintf("typecast_GENERIC_ARRAY_cast: str = '%s',"
" len = " FORMAT_CODE_PY_SSIZE_T, str, len); " 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] == '[') if (str[0] == '[')
typecast_array_cleanup(&str, &len); typecast_array_cleanup(&str, &len);
if (str[0] != '{') { if (str[0] != '{') {

View File

@ -31,7 +31,7 @@ typecast_INTEGER_cast(const char *s, Py_ssize_t len, PyObject *curs)
{ {
char buffer[12]; char buffer[12];
if (s == NULL) {Py_INCREF(Py_None); return Py_None;} if (s == NULL) { Py_RETURN_NONE; }
if (s[len] != '\0') { if (s[len] != '\0') {
strncpy(buffer, s, (size_t) len); buffer[len] = '\0'; strncpy(buffer, s, (size_t) len); buffer[len] = '\0';
s = buffer; s = buffer;
@ -49,7 +49,7 @@ typecast_LONGINTEGER_cast(const char *s, Py_ssize_t len, PyObject *curs)
{ {
char buffer[24]; char buffer[24];
if (s == NULL) {Py_INCREF(Py_None); return Py_None;} if (s == NULL) { Py_RETURN_NONE; }
if (s[len] != '\0') { if (s[len] != '\0') {
strncpy(buffer, s, (size_t) len); buffer[len] = '\0'; strncpy(buffer, s, (size_t) len); buffer[len] = '\0';
s = buffer; s = buffer;
@ -64,7 +64,7 @@ typecast_FLOAT_cast(const char *s, Py_ssize_t len, PyObject *curs)
{ {
PyObject *str = NULL, *flo = NULL; 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 (!(str = Text_FromUTF8AndSize(s, len))) { return NULL; }
#if PY_MAJOR_VERSION < 3 #if PY_MAJOR_VERSION < 3
flo = PyFloat_FromString(str, NULL); flo = PyFloat_FromString(str, NULL);
@ -81,7 +81,7 @@ typecast_FLOAT_cast(const char *s, Py_ssize_t len, PyObject *curs)
static PyObject * static PyObject *
typecast_STRING_cast(const char *s, Py_ssize_t len, PyObject *curs) 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); return PyString_FromStringAndSize(s, len);
} }
#else #else
@ -95,7 +95,7 @@ typecast_UNICODE_cast(const char *s, Py_ssize_t len, PyObject *curs)
{ {
char *enc; char *enc;
if (s == NULL) {Py_INCREF(Py_None); return Py_None;} if (s == NULL) { Py_RETURN_NONE; }
enc = ((cursorObject*)curs)->conn->codec; enc = ((cursorObject*)curs)->conn->codec;
return PyUnicode_Decode(s, len, enc, NULL); 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; PyObject *res;
if (s == NULL) {Py_INCREF(Py_None); return Py_None;} if (s == NULL) { Py_RETURN_NONE; }
if (s[0] == 't') if (s[0] == 't')
res = Py_True; res = Py_True;
@ -128,7 +128,7 @@ typecast_DECIMAL_cast(const char *s, Py_ssize_t len, PyObject *curs)
PyObject *decimalType; PyObject *decimalType;
char *buffer; 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) if ((buffer = PyMem_Malloc(len+1)) == NULL)
return PyErr_NoMemory(); return PyErr_NoMemory();

View File

@ -146,7 +146,7 @@ typecast_BINARY_cast(const char *s, Py_ssize_t l, PyObject *curs)
char *buffer = NULL; char *buffer = NULL;
Py_ssize_t len; 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') { if (s[0] == '\\' && s[1] == 'x') {
/* This is a buffer escaped in hex format: libpq before 9.0 can't /* This is a buffer escaped in hex format: libpq before 9.0 can't

View File

@ -48,7 +48,7 @@ typecast_PYDATE_cast(const char *str, Py_ssize_t len, PyObject *curs)
PyObject* obj = NULL; PyObject* obj = NULL;
int n, y=0, m=0, d=0; 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 (!strcmp(str, "infinity") || !strcmp(str, "-infinity")) {
if (str[0] == '-') { 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; int hh=0, mm=0, ss=0, us=0, tz=0;
const char *tp = NULL; const char *tp = NULL;
if (str == NULL) {Py_INCREF(Py_None); return Py_None;} if (str == NULL) { Py_RETURN_NONE; }
/* check for infinity */ /* check for infinity */
if (!strcmp(str, "infinity") || !strcmp(str, "-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; PyObject *tzinfo_factory;
int n, hh=0, mm=0, ss=0, us=0, tz=0; 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); n = typecast_parse_time(str, NULL, &len, &hh, &mm, &ss, &us, &tz);
Dprintf("typecast_PYTIME_cast: n = %d, len = " FORMAT_CODE_PY_SSIZE_T ", " 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; int part = 0, sec;
double micro; 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); Dprintf("typecast_PYINTERVAL_cast: s = %s", str);

View File

@ -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; int hh=0, mm=0, ss=0, us=0, tz=0;
const char *tp = NULL; 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); 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; 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); 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; double v = 0.0, sign = 1.0;
int part = 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); Dprintf("typecast_MXINTERVAL_cast: s = %s", str);