mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-15 11:10:58 +08:00
More (de)allocation cleanups, based on suggestions from
python-dev and Skip Montanaro
This commit is contained in:
@ -42,6 +42,11 @@ PERFORMANCE OF THIS SOFTWARE.
|
|||||||
#include "mysqld_error.h"
|
#include "mysqld_error.h"
|
||||||
#include "errmsg.h"
|
#include "errmsg.h"
|
||||||
|
|
||||||
|
#if PY_VERSION_HEX < 0x01060000
|
||||||
|
# define PyObject_Del(x) PyMem_Free((char *) x)
|
||||||
|
# define PyObject_New(x,y) PyObject_NEW(x,y)
|
||||||
|
#endif
|
||||||
|
|
||||||
static PyObject *_mysql_MySQLError;
|
static PyObject *_mysql_MySQLError;
|
||||||
static PyObject *_mysql_Warning;
|
static PyObject *_mysql_Warning;
|
||||||
static PyObject *_mysql_Error;
|
static PyObject *_mysql_Error;
|
||||||
@ -160,11 +165,7 @@ _mysql_ResultObject_New(
|
|||||||
MYSQL_FIELD *fields;
|
MYSQL_FIELD *fields;
|
||||||
_mysql_ResultObject *r;
|
_mysql_ResultObject *r;
|
||||||
|
|
||||||
#if PY_VERSION_HEX < 0x02000100
|
|
||||||
r = PyObject_NEW(_mysql_ResultObject, &_mysql_ResultObject_Type);
|
|
||||||
#else
|
|
||||||
r = PyObject_New(_mysql_ResultObject, &_mysql_ResultObject_Type);
|
r = PyObject_New(_mysql_ResultObject, &_mysql_ResultObject_Type);
|
||||||
#endif
|
|
||||||
if (!r) return NULL;
|
if (!r) return NULL;
|
||||||
r->conn = (PyObject *) conn;
|
r->conn = (PyObject *) conn;
|
||||||
r->use = use;
|
r->use = use;
|
||||||
@ -240,13 +241,8 @@ _mysql_connect(
|
|||||||
*read_default_group=NULL;
|
*read_default_group=NULL;
|
||||||
_mysql_ConnectionObject *c=NULL;
|
_mysql_ConnectionObject *c=NULL;
|
||||||
|
|
||||||
#if PY_VERSION_HEX < 0x02000100
|
|
||||||
c = PyObject_NEW(_mysql_ConnectionObject,
|
|
||||||
&_mysql_ConnectionObject_Type);
|
|
||||||
#else
|
|
||||||
c = PyObject_New(_mysql_ConnectionObject,
|
c = PyObject_New(_mysql_ConnectionObject,
|
||||||
&_mysql_ConnectionObject_Type);
|
&_mysql_ConnectionObject_Type);
|
||||||
#endif
|
|
||||||
if (c == NULL) return NULL;
|
if (c == NULL) return NULL;
|
||||||
c->converter = NULL;
|
c->converter = NULL;
|
||||||
c->open = 0;
|
c->open = 0;
|
||||||
@ -1180,11 +1176,7 @@ _mysql_ConnectionObject_dealloc(
|
|||||||
o = _mysql_ConnectionObject_close(self, NULL);
|
o = _mysql_ConnectionObject_close(self, NULL);
|
||||||
Py_XDECREF(o);
|
Py_XDECREF(o);
|
||||||
}
|
}
|
||||||
#if PY_VERSION_HEX < 0x02000100
|
|
||||||
PyMem_Free((char *) self);
|
|
||||||
#else
|
|
||||||
PyObject_Del(self);
|
PyObject_Del(self);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
@ -1255,11 +1247,7 @@ _mysql_ResultObject_dealloc(
|
|||||||
mysql_free_result(self->result);
|
mysql_free_result(self->result);
|
||||||
Py_DECREF(self->conn);
|
Py_DECREF(self->conn);
|
||||||
Py_XDECREF(self->converter);
|
Py_XDECREF(self->converter);
|
||||||
#if PY_VERSION_HEX < 0x02000100
|
|
||||||
PyMem_Free((char *) self);
|
|
||||||
#else
|
|
||||||
PyObject_Del(self);
|
PyObject_Del(self);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
Reference in New Issue
Block a user