Using Py_TYPE and Py_REFCNT macros.

This commit is contained in:
Daniele Varrazzo 2010-12-12 21:31:10 +00:00
parent 2196ff5488
commit 8dfa9915eb
20 changed files with 83 additions and 81 deletions

View File

@ -94,7 +94,7 @@ asis_setup(asisObject *self, PyObject *obj)
{
Dprintf("asis_setup: init asis object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
self, Py_REFCNT(self)
);
Py_INCREF(obj);
@ -102,7 +102,7 @@ asis_setup(asisObject *self, PyObject *obj)
Dprintf("asis_setup: good asis object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
self, Py_REFCNT(self)
);
return 0;
}
@ -123,10 +123,10 @@ asis_dealloc(PyObject* obj)
Dprintf("asis_dealloc: deleted asis object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
obj, obj->ob_refcnt
obj, Py_REFCNT(obj)
);
obj->ob_type->tp_free(obj);
Py_TYPE(obj)->tp_free(obj);
}
static int

View File

@ -172,7 +172,7 @@ binary_setup(binaryObject *self, PyObject *str)
{
Dprintf("binary_setup: init binary object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
self, Py_REFCNT(self)
);
self->buffer = NULL;
@ -182,7 +182,7 @@ binary_setup(binaryObject *self, PyObject *str)
Dprintf("binary_setup: good binary object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt);
self, Py_REFCNT(self));
return 0;
}
@ -208,10 +208,10 @@ binary_dealloc(PyObject* obj)
Dprintf("binary_dealloc: deleted binary object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
obj, obj->ob_refcnt
obj, Py_REFCNT(obj)
);
obj->ob_type->tp_free(obj);
Py_TYPE(obj)->tp_free(obj);
}
static int

View File

@ -154,7 +154,7 @@ pydatetime_setup(pydatetimeObject *self, PyObject *obj, int type)
{
Dprintf("pydatetime_setup: init datetime object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt);
self, Py_REFCNT(self));
self->type = type;
Py_INCREF(obj);
@ -162,7 +162,7 @@ pydatetime_setup(pydatetimeObject *self, PyObject *obj, int type)
Dprintf("pydatetime_setup: good pydatetime object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt);
self, Py_REFCNT(self));
return 0;
}
@ -183,9 +183,9 @@ pydatetime_dealloc(PyObject* obj)
Py_CLEAR(self->wrapped);
Dprintf("mpydatetime_dealloc: deleted pydatetime object at %p, "
"refcnt = " FORMAT_CODE_PY_SSIZE_T, obj, obj->ob_refcnt);
"refcnt = " FORMAT_CODE_PY_SSIZE_T, obj, Py_REFCNT(obj));
obj->ob_type->tp_free(obj);
Py_TYPE(obj)->tp_free(obj);
}
static int

View File

@ -158,7 +158,7 @@ list_setup(listObject *self, PyObject *obj, const char *enc)
{
Dprintf("list_setup: init list object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
self, Py_REFCNT(self)
);
if (!PyList_Check(obj))
@ -173,7 +173,7 @@ list_setup(listObject *self, PyObject *obj, const char *enc)
Dprintf("list_setup: good list object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
self, Py_REFCNT(self)
);
return 0;
}
@ -198,9 +198,9 @@ list_dealloc(PyObject* obj)
if (self->encoding) free(self->encoding);
Dprintf("list_dealloc: deleted list object at %p, "
"refcnt = " FORMAT_CODE_PY_SSIZE_T, obj, obj->ob_refcnt);
"refcnt = " FORMAT_CODE_PY_SSIZE_T, obj, Py_REFCNT(obj));
obj->ob_type->tp_free(obj);
Py_TYPE(obj)->tp_free(obj);
}
static int

View File

@ -158,7 +158,7 @@ mxdatetime_setup(mxdatetimeObject *self, PyObject *obj, int type)
{
Dprintf("mxdatetime_setup: init mxdatetime object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
self, Py_REFCNT(self)
);
self->type = type;
@ -167,7 +167,7 @@ mxdatetime_setup(mxdatetimeObject *self, PyObject *obj, int type)
Dprintf("mxdatetime_setup: good mxdatetime object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
self, Py_REFCNT(self)
);
return 0;
}
@ -190,10 +190,10 @@ mxdatetime_dealloc(PyObject* obj)
Dprintf("mxdatetime_dealloc: deleted mxdatetime object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
obj, obj->ob_refcnt
obj, Py_REFCNT(obj)
);
obj->ob_type->tp_free(obj);
Py_TYPE(obj)->tp_free(obj);
}
static int

View File

@ -103,7 +103,7 @@ pboolean_setup(pbooleanObject *self, PyObject *obj)
{
Dprintf("pboolean_setup: init pboolean object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
self, Py_REFCNT(self)
);
Py_INCREF(obj);
@ -111,7 +111,7 @@ pboolean_setup(pbooleanObject *self, PyObject *obj)
Dprintf("pboolean_setup: good pboolean object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
self, Py_REFCNT(self)
);
return 0;
}
@ -134,10 +134,10 @@ pboolean_dealloc(PyObject* obj)
Dprintf("pboolean_dealloc: deleted pboolean object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
obj, obj->ob_refcnt
obj, Py_REFCNT(obj)
);
obj->ob_type->tp_free(obj);
Py_TYPE(obj)->tp_free(obj);
}
static int

View File

@ -125,7 +125,7 @@ pdecimal_setup(pdecimalObject *self, PyObject *obj)
{
Dprintf("pdecimal_setup: init pdecimal object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
self, Py_REFCNT(self)
);
Py_INCREF(obj);
@ -133,7 +133,7 @@ pdecimal_setup(pdecimalObject *self, PyObject *obj)
Dprintf("pdecimal_setup: good pdecimal object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
self, Py_REFCNT(self)
);
return 0;
}
@ -156,10 +156,10 @@ pdecimal_dealloc(PyObject* obj)
Dprintf("pdecimal_dealloc: deleted pdecimal object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
obj, obj->ob_refcnt
obj, Py_REFCNT(obj)
);
obj->ob_type->tp_free(obj);
Py_TYPE(obj)->tp_free(obj);
}
static int

View File

@ -95,7 +95,7 @@ pfloat_setup(pfloatObject *self, PyObject *obj)
{
Dprintf("pfloat_setup: init pfloat object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
self, Py_REFCNT(self)
);
Py_INCREF(obj);
@ -103,7 +103,7 @@ pfloat_setup(pfloatObject *self, PyObject *obj)
Dprintf("pfloat_setup: good pfloat object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
self, Py_REFCNT(self)
);
return 0;
}
@ -126,10 +126,10 @@ pfloat_dealloc(PyObject* obj)
Dprintf("pfloat_dealloc: deleted pfloat object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
obj, obj->ob_refcnt
obj, Py_REFCNT(obj)
);
obj->ob_type->tp_free(obj);
Py_TYPE(obj)->tp_free(obj);
}
static int

View File

@ -205,7 +205,7 @@ qstring_setup(qstringObject *self, PyObject *str, const char *enc)
{
Dprintf("qstring_setup: init qstring object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
self, Py_REFCNT(self)
);
self->buffer = NULL;
@ -219,7 +219,7 @@ qstring_setup(qstringObject *self, PyObject *str, const char *enc)
Dprintf("qstring_setup: good qstring object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
self, Py_REFCNT(self)
);
return 0;
}
@ -248,10 +248,10 @@ qstring_dealloc(PyObject* obj)
Dprintf("qstring_dealloc: deleted qstring object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
obj, obj->ob_refcnt
obj, Py_REFCNT(obj)
);
obj->ob_type->tp_free(obj);
Py_TYPE(obj)->tp_free(obj);
}
static int

View File

@ -101,7 +101,7 @@ psyco_conn_cursor(connectionObject *self, PyObject *args, PyObject *keywds)
Dprintf("psyco_conn_cursor: new cursor at %p: refcnt = "
FORMAT_CODE_PY_SSIZE_T,
obj, obj->ob_refcnt
obj, Py_REFCNT(obj)
);
return obj;
}
@ -578,7 +578,7 @@ psyco_conn_lobject(connectionObject *self, PyObject *args, PyObject *keywds)
Dprintf("psyco_conn_lobject: new lobject at %p: refcnt = "
FORMAT_CODE_PY_SSIZE_T,
obj, obj->ob_refcnt);
obj, Py_REFCNT(obj));
return obj;
}
@ -846,7 +846,7 @@ connection_setup(connectionObject *self, const char *dsn, long int async)
Dprintf("connection_setup: init connection object at %p, "
"async %ld, refcnt = " FORMAT_CODE_PY_SSIZE_T,
self, async, ((PyObject *)self)->ob_refcnt
self, async, Py_REFCNT(self)
);
self->dsn = strdup(dsn);
@ -875,7 +875,7 @@ connection_setup(connectionObject *self, const char *dsn, long int async)
else {
Dprintf("connection_setup: good connection object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
self, Py_REFCNT(self)
);
res = 0;
}
@ -916,10 +916,10 @@ connection_dealloc(PyObject* obj)
Dprintf("connection_dealloc: deleted connection object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
obj, obj->ob_refcnt
obj, Py_REFCNT(obj)
);
obj->ob_type->tp_free(obj);
Py_TYPE(obj)->tp_free(obj);
}
static int

View File

@ -130,7 +130,7 @@ _mogrify(PyObject *var, PyObject *fmt, connectionObject *conn, PyObject **new)
}
Dprintf("_mogrify: value refcnt: "
FORMAT_CODE_PY_SSIZE_T " (+1)", value->ob_refcnt);
FORMAT_CODE_PY_SSIZE_T " (+1)", Py_REFCNT(value));
if (n == NULL) {
n = PyDict_New();
@ -183,7 +183,7 @@ _mogrify(PyObject *var, PyObject *fmt, connectionObject *conn, PyObject **new)
Py_DECREF(key); /* key has the original refcnt now */
Dprintf("_mogrify: after value refcnt: "
FORMAT_CODE_PY_SSIZE_T,
value->ob_refcnt
Py_REFCNT(value)
);
}
c = d;
@ -594,7 +594,7 @@ _psyco_curs_mogrify(cursorObject *self,
Dprintf("psyco_curs_mogrify: cvt->refcnt = " FORMAT_CODE_PY_SSIZE_T
", fquery->refcnt = " FORMAT_CODE_PY_SSIZE_T,
cvt->ob_refcnt, fquery->ob_refcnt);
Py_REFCNT(cvt), Py_REFCNT(fquery));
}
else {
fquery = operation;
@ -679,7 +679,7 @@ _psyco_curs_buildrow_fill(cursorObject *self, PyObject *res,
if (val) {
Dprintf("_psyco_curs_buildrow: val->refcnt = "
FORMAT_CODE_PY_SSIZE_T,
val->ob_refcnt
Py_REFCNT(val)
);
if (istuple) {
PyTuple_SET_ITEM(res, i, val);
@ -1631,7 +1631,7 @@ cursor_setup(cursorObject *self, connectionObject *conn, const char *name)
Dprintf("cursor_setup: good cursor object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
self, Py_REFCNT(self)
);
return 0;
}
@ -1659,9 +1659,9 @@ cursor_dealloc(PyObject* obj)
Dprintf("cursor_dealloc: deleted cursor object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
obj, obj->ob_refcnt);
obj, Py_REFCNT(obj));
obj->ob_type->tp_free(obj);
Py_TYPE(obj)->tp_free(obj);
}
static int

View File

@ -315,7 +315,7 @@ lobject_setup(lobjectObject *self, connectionObject *conn,
return -1;
Dprintf("lobject_setup: good lobject object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T, self, ((PyObject *)self)->ob_refcnt);
FORMAT_CODE_PY_SSIZE_T, self, Py_REFCNT(self));
Dprintf("lobject_setup: oid = %d, fd = %d", self->oid, self->fd);
return 0;
}
@ -330,9 +330,9 @@ lobject_dealloc(PyObject* obj)
Py_XDECREF((PyObject*)self->conn);
Dprintf("lobject_dealloc: deleted lobject object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T, obj, obj->ob_refcnt);
FORMAT_CODE_PY_SSIZE_T, obj, Py_REFCNT(obj));
obj->ob_type->tp_free(obj);
Py_TYPE(obj)->tp_free(obj);
}
static int

View File

@ -84,7 +84,7 @@ _get_superclass_adapter(PyObject *obj, PyObject *proto)
PyObject *key, *adapter;
Py_ssize_t i, ii;
type = (PyTypeObject *)Py_TYPE(obj);
type = Py_TYPE(obj);
if (!((Py_TPFLAGS_HAVE_CLASS & type->tp_flags) && type->tp_mro)) {
/* has no mro */
return NULL;
@ -138,7 +138,8 @@ microprotocols_adapt(PyObject *obj, PyObject *proto, PyObject *alt)
if (obj == Py_None)
return PyString_FromString("NULL");
Dprintf("microprotocols_adapt: trying to adapt %s", obj->ob_type->tp_name);
Dprintf("microprotocols_adapt: trying to adapt %s",
Py_TYPE(obj)->tp_name);
/* look for an adapter in the registry */
key = PyTuple_Pack(2, Py_TYPE(obj), proto);
@ -194,7 +195,8 @@ microprotocols_adapt(PyObject *obj, PyObject *proto, PyObject *alt)
}
/* else set the right exception and return NULL */
PyOS_snprintf(buffer, 255, "can't adapt type '%s'", obj->ob_type->tp_name);
PyOS_snprintf(buffer, 255, "can't adapt type '%s'",
Py_TYPE(obj)->tp_name);
psyco_set_error(ProgrammingError, NULL, buffer, NULL, NULL);
return NULL;
}
@ -213,7 +215,7 @@ microprotocol_getquoted(PyObject *obj, connectionObject *conn)
}
Dprintf("microprotocol_getquoted: adapted to %s",
adapted->ob_type->tp_name);
Py_TYPE(adapted)->tp_name);
/* if requested prepare the object passing it the connection */
if (conn) {

View File

@ -118,7 +118,7 @@ isqlquote_dealloc(PyObject* obj)
Py_XDECREF(self->wrapped);
obj->ob_type->tp_free(obj);
Py_TYPE(obj)->tp_free(obj);
}
static int

View File

@ -114,7 +114,7 @@ notify_dealloc(NotifyObject *self)
Py_CLEAR(self->channel);
Py_CLEAR(self->payload);
self->ob_type->tp_free((PyObject *)self);
Py_TYPE(self)->tp_free((PyObject *)self);
}
static void

View File

@ -713,20 +713,20 @@ init_psycopg(void)
Dprintf("initpsycopg: initializing psycopg %s", PSYCOPG_VERSION);
/* initialize all the new types and then the module */
connectionType.ob_type = &PyType_Type;
cursorType.ob_type = &PyType_Type;
typecastType.ob_type = &PyType_Type;
qstringType.ob_type = &PyType_Type;
binaryType.ob_type = &PyType_Type;
isqlquoteType.ob_type = &PyType_Type;
pbooleanType.ob_type = &PyType_Type;
pfloatType.ob_type = &PyType_Type;
pdecimalType.ob_type = &PyType_Type;
asisType.ob_type = &PyType_Type;
listType.ob_type = &PyType_Type;
chunkType.ob_type = &PyType_Type;
NotifyType.ob_type = &PyType_Type;
XidType.ob_type = &PyType_Type;
Py_TYPE(&connectionType) = &PyType_Type;
Py_TYPE(&cursorType) = &PyType_Type;
Py_TYPE(&typecastType) = &PyType_Type;
Py_TYPE(&qstringType) = &PyType_Type;
Py_TYPE(&binaryType) = &PyType_Type;
Py_TYPE(&isqlquoteType) = &PyType_Type;
Py_TYPE(&pbooleanType) = &PyType_Type;
Py_TYPE(&pfloatType) = &PyType_Type;
Py_TYPE(&pdecimalType) = &PyType_Type;
Py_TYPE(&asisType) = &PyType_Type;
Py_TYPE(&listType) = &PyType_Type;
Py_TYPE(&chunkType) = &PyType_Type;
Py_TYPE(&NotifyType) = &PyType_Type;
Py_TYPE(&XidType) = &PyType_Type;
if (PyType_Ready(&connectionType) == -1) return;
if (PyType_Ready(&cursorType) == -1) return;
@ -744,13 +744,13 @@ init_psycopg(void)
if (PyType_Ready(&XidType) == -1) return;
#ifdef PSYCOPG_EXTENSIONS
lobjectType.ob_type = &PyType_Type;
Py_TYPE(&lobjectType) = &PyType_Type;
if (PyType_Ready(&lobjectType) == -1) return;
#endif
/* import mx.DateTime module, if necessary */
#ifdef HAVE_MXDATETIME
mxdatetimeType.ob_type = &PyType_Type;
Py_TYPE(&mxdatetimeType) = &PyType_Type;
if (PyType_Ready(&mxdatetimeType) == -1) return;
if (mxDateTime_ImportModuleAndAPI() != 0) {
Dprintf("initpsycopg: why marc hide mx.DateTime again?!");
@ -772,7 +772,7 @@ init_psycopg(void)
PyDateTime_IMPORT;
if (psyco_adapter_datetime_init()) { return; }
pydatetimeType.ob_type = &PyType_Type;
Py_TYPE(&pydatetimeType) = &PyType_Type;
if (PyType_Ready(&pydatetimeType) == -1) return;
/* import psycopg2.tz anyway (TODO: replace with C-level module?) */

View File

@ -309,7 +309,7 @@ typecast_add(PyObject *obj, PyObject *dict, int binary)
Dprintf("typecast_add: object at %p, values refcnt = "
FORMAT_CODE_PY_SSIZE_T,
obj, type->values->ob_refcnt
obj, Py_REFCNT(type->values)
);
if (dict == NULL)
@ -407,7 +407,7 @@ typecast_dealloc(PyObject *obj)
Py_CLEAR(self->pcast);
Py_CLEAR(self->bcast);
obj->ob_type->tp_free(obj);
Py_TYPE(obj)->tp_free(obj);
}
static int
@ -521,7 +521,7 @@ typecast_new(PyObject *name, PyObject *values, PyObject *cast, PyObject *base)
if (obj == NULL) return NULL;
Dprintf("typecast_new: new type at = %p, refcnt = " FORMAT_CODE_PY_SSIZE_T,
obj, obj->ob_refcnt);
obj, Py_REFCNT(obj));
Py_INCREF(values);
obj->values = values;

View File

@ -41,7 +41,7 @@ chunk_dealloc(chunkObject *self)
self->base, self->len
);
PQfreemem(self->base);
self->ob_type->tp_free((PyObject *) self);
Py_TYPE(self)->tp_free((PyObject *)self);
}
static PyObject *

View File

@ -159,7 +159,7 @@ typecast_PYDATETIME_cast(const char *str, Py_ssize_t len, PyObject *curs)
y, m, d, hh, mm, ss, us, tzinfo);
Dprintf("typecast_PYDATETIME_cast: tzinfo: %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
tzinfo, tzinfo->ob_refcnt
tzinfo, Py_REFCNT(tzinfo)
);
Py_DECREF(tzinfo);
}

View File

@ -184,7 +184,7 @@ xid_dealloc(XidObject *self)
Py_CLEAR(self->owner);
Py_CLEAR(self->database);
self->ob_type->tp_free((PyObject *)self);
Py_TYPE(self)->tp_free((PyObject *)self);
}
static void