mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-16 12:27:03 +08:00
Remove threadsafe and embedded build options
This commit is contained in:
149
_mysql.c
149
_mysql.c
@ -91,8 +91,6 @@ typedef struct {
|
||||
|
||||
extern PyTypeObject _mysql_ResultObject_Type;
|
||||
|
||||
static int _mysql_server_init_done = 0;
|
||||
#define check_server_init(x) if (!_mysql_server_init_done) { if (mysql_server_init(0, NULL, NULL)) { _mysql_Exception(NULL); return x; } else { _mysql_server_init_done = 1;} }
|
||||
|
||||
/* According to https://dev.mysql.com/doc/refman/5.1/en/mysql-options.html
|
||||
The MYSQL_OPT_READ_TIMEOUT appear in the version 5.1.12 */
|
||||
@ -107,14 +105,6 @@ _mysql_Exception(_mysql_ConnectionObject *c)
|
||||
int merr;
|
||||
|
||||
if (!(t = PyTuple_New(2))) return NULL;
|
||||
if (!_mysql_server_init_done) {
|
||||
e = _mysql_InternalError;
|
||||
PyTuple_SET_ITEM(t, 0, PyInt_FromLong(-1L));
|
||||
PyTuple_SET_ITEM(t, 1, PyString_FromString("server not initialized"));
|
||||
PyErr_SetObject(e, t);
|
||||
Py_DECREF(t);
|
||||
return NULL;
|
||||
}
|
||||
if (!(c->open)) {
|
||||
/* GH-270: When connection is closed, accessing the c->connection
|
||||
* object may cause SEGV.
|
||||
@ -219,124 +209,6 @@ _mysql_Exception(_mysql_ConnectionObject *c)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char _mysql_server_init__doc__[] =
|
||||
"Initialize embedded server. If this client is not linked against\n\
|
||||
the embedded server library, this function does nothing.\n\
|
||||
\n\
|
||||
args -- sequence of command-line arguments\n\
|
||||
groups -- sequence of groups to use in defaults files\n\
|
||||
";
|
||||
|
||||
static PyObject *_mysql_server_init(
|
||||
PyObject *self,
|
||||
PyObject *args,
|
||||
PyObject *kwargs) {
|
||||
static char *kwlist[] = {"args", "groups", NULL};
|
||||
char **cmd_args_c=NULL, **groups_c=NULL, *s;
|
||||
int cmd_argc=0, i, groupc;
|
||||
PyObject *cmd_args=NULL, *groups=NULL, *ret=NULL, *item;
|
||||
|
||||
if (_mysql_server_init_done) {
|
||||
PyErr_SetString(_mysql_ProgrammingError,
|
||||
"already initialized");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OO", kwlist,
|
||||
&cmd_args, &groups))
|
||||
return NULL;
|
||||
|
||||
if (cmd_args) {
|
||||
if (!PySequence_Check(cmd_args)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"args must be a sequence");
|
||||
goto finish;
|
||||
}
|
||||
cmd_argc = PySequence_Size(cmd_args);
|
||||
if (cmd_argc == -1) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"args could not be sized");
|
||||
goto finish;
|
||||
}
|
||||
cmd_args_c = (char **) PyMem_Malloc(cmd_argc*sizeof(char *));
|
||||
for (i=0; i< cmd_argc; i++) {
|
||||
item = PySequence_GetItem(cmd_args, i);
|
||||
#ifdef IS_PY3K
|
||||
s = PyUnicode_AsUTF8(item);
|
||||
#else
|
||||
s = PyString_AsString(item);
|
||||
#endif
|
||||
|
||||
Py_DECREF(item);
|
||||
if (!s) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"args must contain strings");
|
||||
goto finish;
|
||||
}
|
||||
cmd_args_c[i] = s;
|
||||
}
|
||||
}
|
||||
if (groups) {
|
||||
if (!PySequence_Check(groups)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"groups must be a sequence");
|
||||
goto finish;
|
||||
}
|
||||
groupc = PySequence_Size(groups);
|
||||
if (groupc == -1) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"groups could not be sized");
|
||||
goto finish;
|
||||
}
|
||||
groups_c = (char **) PyMem_Malloc((1+groupc)*sizeof(char *));
|
||||
for (i=0; i< groupc; i++) {
|
||||
item = PySequence_GetItem(groups, i);
|
||||
#ifdef IS_PY3K
|
||||
s = PyUnicode_AsUTF8(item);
|
||||
#else
|
||||
s = PyString_AsString(item);
|
||||
#endif
|
||||
Py_DECREF(item);
|
||||
if (!s) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"groups must contain strings");
|
||||
goto finish;
|
||||
}
|
||||
groups_c[i] = s;
|
||||
}
|
||||
groups_c[groupc] = (char *)NULL;
|
||||
}
|
||||
/* even though this may block, don't give up the interpreter lock
|
||||
so that the server can't be initialized multiple times. */
|
||||
if (mysql_server_init(cmd_argc, cmd_args_c, groups_c)) {
|
||||
_mysql_Exception(NULL);
|
||||
goto finish;
|
||||
}
|
||||
ret = Py_None;
|
||||
Py_INCREF(Py_None);
|
||||
_mysql_server_init_done = 1;
|
||||
finish:
|
||||
PyMem_Free(groups_c);
|
||||
PyMem_Free(cmd_args_c);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static char _mysql_server_end__doc__[] =
|
||||
"Shut down embedded server. If not using an embedded server, this\n\
|
||||
does nothing.";
|
||||
|
||||
static PyObject *_mysql_server_end(
|
||||
PyObject *self,
|
||||
PyObject *args) {
|
||||
if (_mysql_server_init_done) {
|
||||
mysql_server_end();
|
||||
_mysql_server_init_done = 0;
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
return _mysql_Exception(NULL);
|
||||
}
|
||||
|
||||
static char _mysql_thread_safe__doc__[] =
|
||||
"Indicates whether the client is compiled as thread-safe.";
|
||||
|
||||
@ -344,10 +216,7 @@ static PyObject *_mysql_thread_safe(
|
||||
PyObject *self,
|
||||
PyObject *noargs)
|
||||
{
|
||||
PyObject *flag;
|
||||
check_server_init(NULL);
|
||||
if (!(flag=PyInt_FromLong((long)mysql_thread_safe()))) return NULL;
|
||||
return flag;
|
||||
return PyInt_FromLong((long)mysql_thread_safe());
|
||||
}
|
||||
|
||||
static char _mysql_ResultObject__doc__[] =
|
||||
@ -530,7 +399,6 @@ _mysql_ConnectionObject_Initialize(
|
||||
|
||||
self->converter = NULL;
|
||||
self->open = 0;
|
||||
check_server_init(-1);
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
|
||||
#ifdef HAVE_MYSQL_OPT_TIMEOUTS
|
||||
@ -1029,7 +897,6 @@ _mysql_escape_string(
|
||||
str = PyBytes_FromStringAndSize((char *) NULL, size*2+1);
|
||||
if (!str) return PyErr_NoMemory();
|
||||
out = PyBytes_AS_STRING(str);
|
||||
check_server_init(NULL);
|
||||
|
||||
if (self && PyModule_Check((PyObject*)self))
|
||||
self = NULL;
|
||||
@ -1090,7 +957,6 @@ _mysql_string_literal(
|
||||
return PyErr_NoMemory();
|
||||
}
|
||||
out = PyBytes_AS_STRING(str);
|
||||
check_server_init(NULL);
|
||||
if (self && self->open) {
|
||||
#if MYSQL_VERSION_ID >= 50707 && !defined(MARIADB_BASE_VERSION) && !defined(MARIADB_VERSION_ID)
|
||||
len = mysql_real_escape_string_quote(&(self->connection), out+1, in, size, '\'');
|
||||
@ -1715,7 +1581,6 @@ _mysql_get_client_info(
|
||||
PyObject *self,
|
||||
PyObject *noargs)
|
||||
{
|
||||
check_server_init(NULL);
|
||||
return PyString_FromString(mysql_get_client_info());
|
||||
}
|
||||
|
||||
@ -2785,18 +2650,6 @@ _mysql_methods[] = {
|
||||
METH_NOARGS,
|
||||
_mysql_thread_safe__doc__
|
||||
},
|
||||
{
|
||||
"server_init",
|
||||
(PyCFunction)_mysql_server_init,
|
||||
METH_VARARGS | METH_KEYWORDS,
|
||||
_mysql_server_init__doc__
|
||||
},
|
||||
{
|
||||
"server_end",
|
||||
(PyCFunction)_mysql_server_end,
|
||||
METH_VARARGS,
|
||||
_mysql_server_end__doc__
|
||||
},
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user