@@ -92,32 +92,6 @@ isolation_level_converter(PyObject *str_or_none, const char **result)
9292 return 1 ;
9393}
9494
95- static int
96- clinic_fsconverter (PyObject * pathlike , const char * * result )
97- {
98- PyObject * bytes = NULL ;
99- Py_ssize_t len ;
100- char * str ;
101-
102- if (!PyUnicode_FSConverter (pathlike , & bytes )) {
103- goto error ;
104- }
105- if (PyBytes_AsStringAndSize (bytes , & str , & len ) < 0 ) {
106- goto error ;
107- }
108- if ((* result = (const char * )PyMem_Malloc (len + 1 )) == NULL ) {
109- goto error ;
110- }
111-
112- memcpy ((void * )(* result ), str , len + 1 );
113- Py_DECREF (bytes );
114- return 1 ;
115-
116- error :
117- Py_XDECREF (bytes );
118- return 0 ;
119- }
120-
12195#define clinic_state () (pysqlite_get_state_by_type(Py_TYPE(self)))
12296#include "clinic/connection.c.h"
12397#undef clinic_state
@@ -159,25 +133,17 @@ new_statement_cache(pysqlite_Connection *self, pysqlite_state *state,
159133}
160134
161135/*[python input]
162- class FSConverter_converter(CConverter):
163- type = "const char *"
164- converter = "clinic_fsconverter"
165- def converter_init(self):
166- self.c_default = "NULL"
167- def cleanup(self):
168- return f"PyMem_Free((void *){self.name});\n"
169-
170136class IsolationLevel_converter(CConverter):
171137 type = "const char *"
172138 converter = "isolation_level_converter"
173139
174140[python start generated code]*/
175- /*[python end generated code: output=da39a3ee5e6b4b0d input=be142323885672ab ]*/
141+ /*[python end generated code: output=da39a3ee5e6b4b0d input=cbcfe85b253061c2 ]*/
176142
177143/*[clinic input]
178144_sqlite3.Connection.__init__ as pysqlite_connection_init
179145
180- database: FSConverter
146+ database: object
181147 timeout: double = 5.0
182148 detect_types: int = 0
183149 isolation_level: IsolationLevel = ""
@@ -188,14 +154,19 @@ _sqlite3.Connection.__init__ as pysqlite_connection_init
188154[clinic start generated code]*/
189155
190156static int
191- pysqlite_connection_init_impl (pysqlite_Connection * self ,
192- const char * database , double timeout ,
193- int detect_types , const char * isolation_level ,
157+ pysqlite_connection_init_impl (pysqlite_Connection * self , PyObject * database ,
158+ double timeout , int detect_types ,
159+ const char * isolation_level ,
194160 int check_same_thread , PyObject * factory ,
195161 int cache_size , int uri )
196- /*[clinic end generated code: output=7d640ae1d83abfd4 input=342173993434ba1e ]*/
162+ /*[clinic end generated code: output=839eb2fee4293bda input=b8ce63dc6f70a383 ]*/
197163{
198- if (PySys_Audit ("sqlite3.connect" , "s" , database ) < 0 ) {
164+ if (PySys_Audit ("sqlite3.connect" , "O" , database ) < 0 ) {
165+ return -1 ;
166+ }
167+
168+ PyObject * bytes ;
169+ if (!PyUnicode_FSConverter (database , & bytes )) {
199170 return -1 ;
200171 }
201172
@@ -210,14 +181,15 @@ pysqlite_connection_init_impl(pysqlite_Connection *self,
210181 sqlite3 * db ;
211182 int rc ;
212183 Py_BEGIN_ALLOW_THREADS
213- rc = sqlite3_open_v2 (database , & db ,
184+ rc = sqlite3_open_v2 (PyBytes_AS_STRING ( bytes ) , & db ,
214185 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE |
215186 (uri ? SQLITE_OPEN_URI : 0 ), NULL );
216187 if (rc == SQLITE_OK ) {
217188 (void )sqlite3_busy_timeout (db , (int )(timeout * 1000 ));
218189 }
219190 Py_END_ALLOW_THREADS
220191
192+ Py_DECREF (bytes );
221193 if (db == NULL && rc == SQLITE_NOMEM ) {
222194 PyErr_NoMemory ();
223195 return -1 ;
0 commit comments