33
33
#define HAVE_TRACE_V2
34
34
#endif
35
35
36
+ static int
37
+ clinic_fsconverter (PyObject * pathlike , const char * * result )
38
+ {
39
+ PyObject * bytes = NULL ;
40
+ Py_ssize_t len ;
41
+ char * str ;
42
+
43
+ if (!PyUnicode_FSConverter (pathlike , & bytes )) {
44
+ goto error ;
45
+ }
46
+ if (PyBytes_AsStringAndSize (bytes , & str , & len ) < 0 ) {
47
+ goto error ;
48
+ }
49
+ if ((* result = (const char * )PyMem_Malloc (len + 1 )) == NULL ) {
50
+ goto error ;
51
+ }
52
+
53
+ memcpy ((void * )(* result ), str , len + 1 );
54
+ Py_DECREF (bytes );
55
+ return 1 ;
56
+
57
+ error :
58
+ Py_XDECREF (bytes );
59
+ return 0 ;
60
+ }
61
+
36
62
#define clinic_state () (pysqlite_get_state(NULL))
37
63
#include "clinic/connection.c.h"
38
64
#undef clinic_state
@@ -81,10 +107,21 @@ new_statement_cache(pysqlite_Connection *self, int maxsize)
81
107
return res ;
82
108
}
83
109
110
+ /*[python input]
111
+ class FSConverter_converter(CConverter):
112
+ type = "const char *"
113
+ converter = "clinic_fsconverter"
114
+ def converter_init(self):
115
+ self.c_default = "NULL"
116
+ def cleanup(self):
117
+ return f"PyMem_Free((void *){self.name});\n"
118
+ [python start generated code]*/
119
+ /*[python end generated code: output=da39a3ee5e6b4b0d input=7b3be538bc4058c0]*/
120
+
84
121
/*[clinic input]
85
122
_sqlite3.Connection.__init__ as pysqlite_connection_init
86
123
87
- database as database_obj: object(converter='PyUnicode_FSConverter')
124
+ database: FSConverter
88
125
timeout: double = 5.0
89
126
detect_types: int = 0
90
127
isolation_level: object = NULL
@@ -96,23 +133,21 @@ _sqlite3.Connection.__init__ as pysqlite_connection_init
96
133
97
134
static int
98
135
pysqlite_connection_init_impl (pysqlite_Connection * self ,
99
- PyObject * database_obj , double timeout ,
136
+ const char * database , double timeout ,
100
137
int detect_types , PyObject * isolation_level ,
101
138
int check_same_thread , PyObject * factory ,
102
139
int cached_statements , int uri )
103
- /*[clinic end generated code: output=dc19df1c0e2b7b77 input=aa1f21bf12fe907a ]*/
140
+ /*[clinic end generated code: output=bc39e55eb0b68783 input=f8d1f7efc0d84104 ]*/
104
141
{
105
142
int rc ;
106
143
107
- if (PySys_Audit ("sqlite3.connect" , "O " , database_obj ) < 0 ) {
144
+ if (PySys_Audit ("sqlite3.connect" , "s " , database ) < 0 ) {
108
145
return -1 ;
109
146
}
110
147
111
148
pysqlite_state * state = pysqlite_get_state_by_type (Py_TYPE (self ));
112
149
self -> state = state ;
113
150
114
- const char * database = PyBytes_AsString (database_obj );
115
-
116
151
self -> begin_statement = NULL ;
117
152
118
153
Py_CLEAR (self -> statement_cache );
@@ -130,8 +165,6 @@ pysqlite_connection_init_impl(pysqlite_Connection *self,
130
165
(uri ? SQLITE_OPEN_URI : 0 ), NULL );
131
166
Py_END_ALLOW_THREADS
132
167
133
- Py_DECREF (database_obj ); // needed bco. the AC FSConverter
134
-
135
168
if (rc != SQLITE_OK ) {
136
169
_pysqlite_seterror (state , self -> db );
137
170
return -1 ;
0 commit comments