Remove threadsafe and embedded build options

This commit is contained in:
INADA Naoki
2018-10-29 19:33:43 +09:00
committed by Inada Naoki
parent 40b8809c8f
commit 354b60145d
6 changed files with 15 additions and 221 deletions

View File

@ -42,16 +42,6 @@ Depending on which version of MySQL you have, you may have the option
of using three different client libraries. To select the client library,
edit the [options] section of site.cfg:
embedded
use embedded server library (libmysqld) if True; otherwise use
one of the client libraries (default).
threadsafe
thread-safe client library (libmysqlclient_r) if True (default);
otherwise use non-thread-safe (libmysqlclient). You should
always use the thread-safe library if you have the option;
otherwise you *may* have problems.
static
if True, try to link against a static library; otherwise link
against dynamic libraries (default). You may need static linking
@ -169,4 +159,3 @@ GPL or the original license based on Python 1.5.2's license.
:Author: Andy Dustman <andy@dustman.net>
:Revision: $Id$

149
_mysql.c
View File

@ -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 */
};

View File

@ -9,13 +9,6 @@
Build Errors
------------
ld: fatal: library -lmysqlclient_r: not found
mysqlclient_r is the thread-safe library. It's not available on
all platforms, or all installations, apparently. You'll need to
reconfigure site.cfg (in MySQLdb-1.2.1 and newer) to have
threadsafe = False.
mysql.h: No such file or directory
This almost always mean you don't have development packages

View File

@ -680,33 +680,6 @@ SSDictCursor
Like ``SSCursor`` except it returns rows as dictionaries.
Embedded Server
---------------
Instead of connecting to a stand-alone server over the network,
the embedded server support lets you run a full server right in
your Python code or application server.
If you have built MySQLdb with embedded server support, there
are two additional functions you will need to make use of:
server_init(args, groups)
Initialize embedded server. If this client is not linked against
the embedded server library, this function does nothing.
args
sequence of command-line arguments
groups
sequence of groups to use in defaults files
server_end()
Shut down embedded server. If not using an embedded server, this
does nothing.
See the MySQL documentation for more information on the embedded
server.
:Title: MySQLdb: a Python interface for MySQL
:Author: Andy Dustman

View File

@ -2,7 +2,6 @@ import os, sys
try:
from ConfigParser import SafeConfigParser
except ImportError:
# Probably running Python 3.x
from configparser import ConfigParser as SafeConfigParser
# This dequote() business is required for some older versions
@ -15,27 +14,29 @@ def dequote(s):
s = s[1:-1]
return s
_mysql_config_path = "mysql_config"
def mysql_config(what):
from os import popen
f = popen("%s --%s" % (mysql_config.path, what))
f = popen("%s --%s" % (_mysql_config_path, what))
data = f.read().strip().split()
ret = f.close()
if ret:
if ret/256:
data = []
if ret/256 > 1:
raise EnvironmentError("%s not found" % (mysql_config.path,))
raise EnvironmentError("%s not found" % (_mysql_config_path,))
return data
mysql_config.path = "mysql_config"
def get_config():
from setup_common import get_metadata_and_options, enabled, create_release_file
global _mysql_config_path
metadata, options = get_metadata_and_options()
if 'mysql_config' in options:
mysql_config.path = options['mysql_config']
_mysql_config_path = options['mysql_config']
extra_objects = []
static = enabled(options, 'static')
@ -47,15 +48,7 @@ def get_config():
static = True
sys.argv.remove('--static')
if enabled(options, 'embedded'):
libs = mysql_config("libmysqld-libs")
elif enabled(options, 'threadsafe'):
libs = mysql_config("libs_r")
if not libs:
libs = mysql_config("libs")
else:
libs = mysql_config("libs")
library_dirs = [dequote(i[2:]) for i in libs if i.startswith('-L')]
libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
extra_link_args = [x for x in libs if not x.startswith(('-l', '-L'))]
@ -92,8 +85,6 @@ def get_config():
libraries.remove(client)
name = "mysqlclient"
if enabled(options, 'embedded'):
name = name + "-embedded"
metadata['name'] = name
define_macros = [

View File

@ -1,10 +1,5 @@
[options]
# embedded: link against the embedded server library
# threadsafe: use the threadsafe client
# static: link against a static library (probably required for embedded)
embedded = False
threadsafe = True
# static: link against a static library
static = False
# The path to mysql_config.