bpo-40956: Convert sqlite3.connect and sqlite3.Connection.__init__ to AC (GH-24421)

This commit is contained in:
Erlend Egeberg Aasland 2021-06-20 21:24:00 +02:00 committed by GitHub
parent 09eb817115
commit 185ecdc146
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 298 additions and 71 deletions

View file

@ -79,40 +79,34 @@ new_statement_cache(pysqlite_Connection *self, int maxsize)
return res;
}
/*[clinic input]
_sqlite3.Connection.__init__ as pysqlite_connection_init
database as database_obj: object(converter='PyUnicode_FSConverter')
timeout: double = 5.0
detect_types: int = 0
isolation_level: object = NULL
check_same_thread: bool(accept={int}) = True
factory: object(c_default='(PyObject*)clinic_state()->ConnectionType') = ConnectionType
cached_statements: int = 128
uri: bool = False
[clinic start generated code]*/
static int
pysqlite_connection_init(pysqlite_Connection *self, PyObject *args,
PyObject *kwargs)
pysqlite_connection_init_impl(pysqlite_Connection *self,
PyObject *database_obj, double timeout,
int detect_types, PyObject *isolation_level,
int check_same_thread, PyObject *factory,
int cached_statements, int uri)
/*[clinic end generated code: output=dc19df1c0e2b7b77 input=aa1f21bf12fe907a]*/
{
static char *kwlist[] = {
"database", "timeout", "detect_types", "isolation_level",
"check_same_thread", "factory", "cached_statements", "uri",
NULL
};
const char* database;
PyObject* database_obj;
int detect_types = 0;
PyObject* isolation_level = NULL;
PyObject* factory = NULL;
int check_same_thread = 1;
int cached_statements = 128;
int uri = 0;
double timeout = 5.0;
int rc;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|diOiOip", kwlist,
PyUnicode_FSConverter, &database_obj, &timeout, &detect_types,
&isolation_level, &check_same_thread,
&factory, &cached_statements, &uri))
{
return -1;
}
if (PySys_Audit("sqlite3.connect", "O", database_obj) < 0) {
return -1;
}
database = PyBytes_AsString(database_obj);
const char *database = PyBytes_AsString(database_obj);
self->initialized = 1;
@ -134,7 +128,7 @@ pysqlite_connection_init(pysqlite_Connection *self, PyObject *args,
(uri ? SQLITE_OPEN_URI : 0), NULL);
Py_END_ALLOW_THREADS
Py_DECREF(database_obj);
Py_DECREF(database_obj); // needed bco. the AC FSConverter
if (rc != SQLITE_OK) {
_pysqlite_seterror(self->db);