@@ -92,32 +92,6 @@ isolation_level_converter(PyObject *str_or_none, const char **result)
92
92
return 1 ;
93
93
}
94
94
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
-
121
95
#define clinic_state () (pysqlite_get_state_by_type(Py_TYPE(self)))
122
96
#include "clinic/connection.c.h"
123
97
#undef clinic_state
@@ -159,25 +133,17 @@ new_statement_cache(pysqlite_Connection *self, pysqlite_state *state,
159
133
}
160
134
161
135
/*[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
-
170
136
class IsolationLevel_converter(CConverter):
171
137
type = "const char *"
172
138
converter = "isolation_level_converter"
173
139
174
140
[python start generated code]*/
175
- /*[python end generated code: output=da39a3ee5e6b4b0d input=be142323885672ab ]*/
141
+ /*[python end generated code: output=da39a3ee5e6b4b0d input=cbcfe85b253061c2 ]*/
176
142
177
143
/*[clinic input]
178
144
_sqlite3.Connection.__init__ as pysqlite_connection_init
179
145
180
- database: FSConverter
146
+ database: object
181
147
timeout: double = 5.0
182
148
detect_types: int = 0
183
149
isolation_level: IsolationLevel = ""
@@ -188,14 +154,19 @@ _sqlite3.Connection.__init__ as pysqlite_connection_init
188
154
[clinic start generated code]*/
189
155
190
156
static 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 ,
194
160
int check_same_thread , PyObject * factory ,
195
161
int cache_size , int uri )
196
- /*[clinic end generated code: output=7d640ae1d83abfd4 input=342173993434ba1e ]*/
162
+ /*[clinic end generated code: output=839eb2fee4293bda input=b8ce63dc6f70a383 ]*/
197
163
{
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 )) {
199
170
return -1 ;
200
171
}
201
172
@@ -210,14 +181,15 @@ pysqlite_connection_init_impl(pysqlite_Connection *self,
210
181
sqlite3 * db ;
211
182
int rc ;
212
183
Py_BEGIN_ALLOW_THREADS
213
- rc = sqlite3_open_v2 (database , & db ,
184
+ rc = sqlite3_open_v2 (PyBytes_AS_STRING ( bytes ) , & db ,
214
185
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE |
215
186
(uri ? SQLITE_OPEN_URI : 0 ), NULL );
216
187
if (rc == SQLITE_OK ) {
217
188
(void )sqlite3_busy_timeout (db , (int )(timeout * 1000 ));
218
189
}
219
190
Py_END_ALLOW_THREADS
220
191
192
+ Py_DECREF (bytes );
221
193
if (db == NULL && rc == SQLITE_NOMEM ) {
222
194
PyErr_NoMemory ();
223
195
return -1 ;
0 commit comments