@@ -91,8 +91,6 @@ typedef struct {
91
91
92
92
extern PyTypeObject _mysql_ResultObject_Type ;
93
93
94
- static int _mysql_server_init_done = 0 ;
95
- #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;} }
96
94
97
95
/* According to https://dev.mysql.com/doc/refman/5.1/en/mysql-options.html
98
96
The MYSQL_OPT_READ_TIMEOUT appear in the version 5.1.12 */
@@ -107,14 +105,6 @@ _mysql_Exception(_mysql_ConnectionObject *c)
107
105
int merr ;
108
106
109
107
if (!(t = PyTuple_New (2 ))) return NULL ;
110
- if (!_mysql_server_init_done ) {
111
- e = _mysql_InternalError ;
112
- PyTuple_SET_ITEM (t , 0 , PyInt_FromLong (-1L ));
113
- PyTuple_SET_ITEM (t , 1 , PyString_FromString ("server not initialized" ));
114
- PyErr_SetObject (e , t );
115
- Py_DECREF (t );
116
- return NULL ;
117
- }
118
108
if (!(c -> open )) {
119
109
/* GH-270: When connection is closed, accessing the c->connection
120
110
* object may cause SEGV.
@@ -219,135 +209,14 @@ _mysql_Exception(_mysql_ConnectionObject *c)
219
209
return NULL ;
220
210
}
221
211
222
- static char _mysql_server_init__doc__ [] =
223
- "Initialize embedded server. If this client is not linked against\n\
224
- the embedded server library, this function does nothing.\n\
225
- \n\
226
- args -- sequence of command-line arguments\n\
227
- groups -- sequence of groups to use in defaults files\n\
228
- " ;
229
-
230
- static PyObject * _mysql_server_init (
231
- PyObject * self ,
232
- PyObject * args ,
233
- PyObject * kwargs ) {
234
- static char * kwlist [] = {"args" , "groups" , NULL };
235
- char * * cmd_args_c = NULL , * * groups_c = NULL , * s ;
236
- int cmd_argc = 0 , i , groupc ;
237
- PyObject * cmd_args = NULL , * groups = NULL , * ret = NULL , * item ;
238
-
239
- if (_mysql_server_init_done ) {
240
- PyErr_SetString (_mysql_ProgrammingError ,
241
- "already initialized" );
242
- return NULL ;
243
- }
244
-
245
- if (!PyArg_ParseTupleAndKeywords (args , kwargs , "|OO" , kwlist ,
246
- & cmd_args , & groups ))
247
- return NULL ;
248
-
249
- if (cmd_args ) {
250
- if (!PySequence_Check (cmd_args )) {
251
- PyErr_SetString (PyExc_TypeError ,
252
- "args must be a sequence" );
253
- goto finish ;
254
- }
255
- cmd_argc = PySequence_Size (cmd_args );
256
- if (cmd_argc == -1 ) {
257
- PyErr_SetString (PyExc_TypeError ,
258
- "args could not be sized" );
259
- goto finish ;
260
- }
261
- cmd_args_c = (char * * ) PyMem_Malloc (cmd_argc * sizeof (char * ));
262
- for (i = 0 ; i < cmd_argc ; i ++ ) {
263
- item = PySequence_GetItem (cmd_args , i );
264
- #ifdef IS_PY3K
265
- s = PyUnicode_AsUTF8 (item );
266
- #else
267
- s = PyString_AsString (item );
268
- #endif
269
-
270
- Py_DECREF (item );
271
- if (!s ) {
272
- PyErr_SetString (PyExc_TypeError ,
273
- "args must contain strings" );
274
- goto finish ;
275
- }
276
- cmd_args_c [i ] = s ;
277
- }
278
- }
279
- if (groups ) {
280
- if (!PySequence_Check (groups )) {
281
- PyErr_SetString (PyExc_TypeError ,
282
- "groups must be a sequence" );
283
- goto finish ;
284
- }
285
- groupc = PySequence_Size (groups );
286
- if (groupc == -1 ) {
287
- PyErr_SetString (PyExc_TypeError ,
288
- "groups could not be sized" );
289
- goto finish ;
290
- }
291
- groups_c = (char * * ) PyMem_Malloc ((1 + groupc )* sizeof (char * ));
292
- for (i = 0 ; i < groupc ; i ++ ) {
293
- item = PySequence_GetItem (groups , i );
294
- #ifdef IS_PY3K
295
- s = PyUnicode_AsUTF8 (item );
296
- #else
297
- s = PyString_AsString (item );
298
- #endif
299
- Py_DECREF (item );
300
- if (!s ) {
301
- PyErr_SetString (PyExc_TypeError ,
302
- "groups must contain strings" );
303
- goto finish ;
304
- }
305
- groups_c [i ] = s ;
306
- }
307
- groups_c [groupc ] = (char * )NULL ;
308
- }
309
- /* even though this may block, don't give up the interpreter lock
310
- so that the server can't be initialized multiple times. */
311
- if (mysql_server_init (cmd_argc , cmd_args_c , groups_c )) {
312
- _mysql_Exception (NULL );
313
- goto finish ;
314
- }
315
- ret = Py_None ;
316
- Py_INCREF (Py_None );
317
- _mysql_server_init_done = 1 ;
318
- finish :
319
- PyMem_Free (groups_c );
320
- PyMem_Free (cmd_args_c );
321
- return ret ;
322
- }
323
-
324
- static char _mysql_server_end__doc__ [] =
325
- "Shut down embedded server. If not using an embedded server, this\n\
326
- does nothing." ;
327
-
328
- static PyObject * _mysql_server_end (
329
- PyObject * self ,
330
- PyObject * args ) {
331
- if (_mysql_server_init_done ) {
332
- mysql_server_end ();
333
- _mysql_server_init_done = 0 ;
334
- Py_INCREF (Py_None );
335
- return Py_None ;
336
- }
337
- return _mysql_Exception (NULL );
338
- }
339
-
340
212
static char _mysql_thread_safe__doc__ [] =
341
213
"Indicates whether the client is compiled as thread-safe." ;
342
214
343
215
static PyObject * _mysql_thread_safe (
344
216
PyObject * self ,
345
217
PyObject * noargs )
346
218
{
347
- PyObject * flag ;
348
- check_server_init (NULL );
349
- if (!(flag = PyInt_FromLong ((long )mysql_thread_safe ()))) return NULL ;
350
- return flag ;
219
+ return PyInt_FromLong ((long )mysql_thread_safe ());
351
220
}
352
221
353
222
static char _mysql_ResultObject__doc__ [] =
@@ -530,7 +399,6 @@ _mysql_ConnectionObject_Initialize(
530
399
531
400
self -> converter = NULL ;
532
401
self -> open = 0 ;
533
- check_server_init (-1 );
534
402
535
403
if (!PyArg_ParseTupleAndKeywords (args , kwargs ,
536
404
#ifdef HAVE_MYSQL_OPT_TIMEOUTS
@@ -1029,7 +897,6 @@ _mysql_escape_string(
1029
897
str = PyBytes_FromStringAndSize ((char * ) NULL , size * 2 + 1 );
1030
898
if (!str ) return PyErr_NoMemory ();
1031
899
out = PyBytes_AS_STRING (str );
1032
- check_server_init (NULL );
1033
900
1034
901
if (self && PyModule_Check ((PyObject * )self ))
1035
902
self = NULL ;
@@ -1090,7 +957,6 @@ _mysql_string_literal(
1090
957
return PyErr_NoMemory ();
1091
958
}
1092
959
out = PyBytes_AS_STRING (str );
1093
- check_server_init (NULL );
1094
960
if (self && self -> open ) {
1095
961
#if MYSQL_VERSION_ID >= 50707 && !defined(MARIADB_BASE_VERSION ) && !defined(MARIADB_VERSION_ID )
1096
962
len = mysql_real_escape_string_quote (& (self -> connection ), out + 1 , in , size , '\'' );
@@ -1715,7 +1581,6 @@ _mysql_get_client_info(
1715
1581
PyObject * self ,
1716
1582
PyObject * noargs )
1717
1583
{
1718
- check_server_init (NULL );
1719
1584
return PyString_FromString (mysql_get_client_info ());
1720
1585
}
1721
1586
@@ -2785,18 +2650,6 @@ _mysql_methods[] = {
2785
2650
METH_NOARGS ,
2786
2651
_mysql_thread_safe__doc__
2787
2652
},
2788
- {
2789
- "server_init" ,
2790
- (PyCFunction )_mysql_server_init ,
2791
- METH_VARARGS | METH_KEYWORDS ,
2792
- _mysql_server_init__doc__
2793
- },
2794
- {
2795
- "server_end" ,
2796
- (PyCFunction )_mysql_server_end ,
2797
- METH_VARARGS ,
2798
- _mysql_server_end__doc__
2799
- },
2800
2653
{NULL , NULL } /* sentinel */
2801
2654
};
2802
2655
0 commit comments