summaryrefslogtreecommitdiff
path: root/psycopg/adapter_qstring.c
diff options
context:
space:
mode:
authorFederico Di Gregorio <fog@initd.org>2007-04-10 06:36:18 +0000
committerFederico Di Gregorio <fog@initd.org>2007-04-10 06:36:18 +0000
commite5829292cdecd56e883733aee552d6fe2121c6ac (patch)
treec7d26880bf00e83d28e65f90aaaf5a581a33796c /psycopg/adapter_qstring.c
parentfadd1a69386ae83ef316f3aee03b2867d8d9fe12 (diff)
downloadpsycopg2-e5829292cdecd56e883733aee552d6fe2121c6ac.tar.gz
Fixed both Python 2.5 and 64 bit problems.
Diffstat (limited to 'psycopg/adapter_qstring.c')
-rw-r--r--psycopg/adapter_qstring.c63
1 files changed, 35 insertions, 28 deletions
diff --git a/psycopg/adapter_qstring.c b/psycopg/adapter_qstring.c
index 90775dc..bb21ad8 100644
--- a/psycopg/adapter_qstring.c
+++ b/psycopg/adapter_qstring.c
@@ -19,6 +19,7 @@
* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <structmember.h>
#include <stringobject.h>
@@ -100,7 +101,7 @@ qstring_quote(qstringObject *self)
/* TODO: we need a real translation table from postgres encoding names to
python ones here */
-
+
Dprintf("qstring_quote: encoding to %s", self->encoding);
if (PyUnicode_Check(self->wrapped) && self->encoding) {
@@ -129,8 +130,8 @@ qstring_quote(qstringObject *self)
/* INCREF to make it ref-wise identical to unicode one */
Py_INCREF(str);
}
-
- /* if the wrapped object is not a string, this is an error */
+
+ /* if the wrapped object is not a string, this is an error */
else {
PyErr_SetString(PyExc_TypeError,
"can't quote non-string object (or missing encoding)");
@@ -139,7 +140,7 @@ qstring_quote(qstringObject *self)
/* encode the string into buffer */
PyString_AsStringAndSize(str, &s, &len);
-
+
buffer = (char *)PyMem_Malloc((len*2+3) * sizeof(char));
if (buffer == NULL) {
Py_DECREF(str);
@@ -152,11 +153,11 @@ qstring_quote(qstringObject *self)
self->conn ? ((connectionObject*)self->conn)->pgconn : NULL);
buffer[0] = '\'' ; buffer[len+1] = '\'';
Py_END_ALLOW_THREADS;
-
+
self->buffer = PyString_FromStringAndSize(buffer, len+2);
PyMem_Free(buffer);
Py_DECREF(str);
-
+
return self->buffer;
}
@@ -204,19 +205,19 @@ qstring_prepare(qstringObject *self, PyObject *args)
Py_INCREF(Py_None);
return Py_None;
}
-
+
PyObject *
qstring_conform(qstringObject *self, PyObject *args)
{
PyObject *res, *proto;
-
+
if (!PyArg_ParseTuple(args, "O", &proto)) return NULL;
if (proto == (PyObject*)&isqlquoteType)
res = (PyObject*)self;
else
res = Py_None;
-
+
Py_INCREF(res);
return res;
}
@@ -248,20 +249,24 @@ static PyMethodDef qstringObject_methods[] = {
static int
qstring_setup(qstringObject *self, PyObject *str, char *enc)
{
- Dprintf("qstring_setup: init qstring object at %p, refcnt = %d",
- self, ((PyObject *)self)->ob_refcnt);
+ Dprintf("qstring_setup: init qstring object at %p, refcnt = "
+ FORMAT_CODE_PY_SSIZE_T,
+ self, ((PyObject *)self)->ob_refcnt
+ );
self->buffer = NULL;
self->conn = NULL;
/* FIXME: remove this orrible strdup */
if (enc) self->encoding = strdup(enc);
-
+
self->wrapped = str;
Py_INCREF(self->wrapped);
-
- Dprintf("qstring_setup: good qstring object at %p, refcnt = %d",
- self, ((PyObject *)self)->ob_refcnt);
+
+ Dprintf("qstring_setup: good qstring object at %p, refcnt = "
+ FORMAT_CODE_PY_SSIZE_T,
+ self, ((PyObject *)self)->ob_refcnt
+ );
return 0;
}
@@ -275,10 +280,12 @@ qstring_dealloc(PyObject* obj)
Py_XDECREF(self->conn);
if (self->encoding) free(self->encoding);
-
- Dprintf("qstring_dealloc: deleted qstring object at %p, refcnt = %d",
- obj, obj->ob_refcnt);
-
+
+ Dprintf("qstring_dealloc: deleted qstring object at %p, refcnt = "
+ FORMAT_CODE_PY_SSIZE_T,
+ obj, obj->ob_refcnt
+ );
+
obj->ob_type->tp_free(obj);
}
@@ -287,7 +294,7 @@ qstring_init(PyObject *obj, PyObject *args, PyObject *kwds)
{
PyObject *str;
char *enc = "latin-1"; /* default encoding as in Python */
-
+
if (!PyArg_ParseTuple(args, "O|s", &str, &enc))
return -1;
@@ -296,7 +303,7 @@ qstring_init(PyObject *obj, PyObject *args, PyObject *kwds)
static PyObject *
qstring_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
+{
return type->tp_alloc(type, 0);
}
@@ -309,7 +316,7 @@ qstring_del(PyObject* self)
static PyObject *
qstring_repr(qstringObject *self)
{
- return PyString_FromFormat("<psycopg2._psycopg.QuotedString object at %p>",
+ return PyString_FromFormat("<psycopg2._psycopg.QuotedString object at %p>",
self);
}
@@ -327,7 +334,7 @@ PyTypeObject qstringType = {
qstring_dealloc, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
- 0, /*tp_setattr*/
+ 0, /*tp_setattr*/
0, /*tp_compare*/
(reprfunc)qstring_repr, /*tp_repr*/
@@ -345,7 +352,7 @@ PyTypeObject qstringType = {
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/
qstringType_doc, /*tp_doc*/
-
+
0, /*tp_traverse*/
0, /*tp_clear*/
@@ -362,11 +369,11 @@ PyTypeObject qstringType = {
0, /*tp_getset*/
0, /*tp_base*/
0, /*tp_dict*/
-
+
0, /*tp_descr_get*/
0, /*tp_descr_set*/
0, /*tp_dictoffset*/
-
+
qstring_init, /*tp_init*/
0, /*tp_alloc will be set to PyType_GenericAlloc in module init*/
qstring_new, /*tp_new*/
@@ -387,9 +394,9 @@ psyco_QuotedString(PyObject *module, PyObject *args)
{
PyObject *str;
char *enc = "latin-1"; /* default encoding as in Python */
-
+
if (!PyArg_ParseTuple(args, "O|s", &str, &enc))
return NULL;
-
+
return PyObject_CallFunction((PyObject *)&qstringType, "Os", str, enc);
}