Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fa9a121

Browse files
committed
"Fix" a few places that were using PyObject_AsCharBuffer() to convert a string
(PyUnicode these days) to a char* + length. The fix consists of calling PyUnicode_AsString() and strlen(). This is not ideal, but AsCharBuffer() is definitely not the API to use.
1 parent 625cbf2 commit fa9a121

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

Modules/_sqlite/cursor.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,10 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
497497
rc = pysqlite_statement_reset(self->statement);
498498
}
499499

500-
if (PyObject_AsCharBuffer(operation, &operation_cstr, &operation_len) < 0)
500+
operation_cstr = PyUnicode_AsString(operation);
501+
if (operation == NULL)
501502
goto error;
503+
operation_len = strlen(operation_cstr); /* XXX */
502504

503505
/* reset description and rowcount */
504506
Py_DECREF(self->description);

Modules/_sqlite/statement.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con
5050
self->st = NULL;
5151
self->in_use = 0;
5252

53-
if (PyObject_AsCharBuffer(sql, &sql_cstr, &sql_cstr_len) < 0) {
53+
sql_cstr = PyUnicode_AsString(sql);
54+
if (sql_cstr == NULL) {
5455
rc = PYSQLITE_SQL_WRONG_TYPE;
5556
return rc;
5657
}
58+
sql_cstr_len = strlen(sql_cstr); /* XXX */
5759

5860
self->in_weakreflist = NULL;
5961
Py_INCREF(sql);
@@ -214,10 +216,12 @@ int pysqlite_statement_recompile(pysqlite_Statement* self, PyObject* params)
214216
Py_ssize_t sql_len;
215217
sqlite3_stmt* new_st;
216218

217-
if (PyObject_AsCharBuffer(self->sql, &sql_cstr, &sql_len) < 0) {
219+
sql_cstr = PyUnicode_AsString(self->sql);
220+
if (sql_cstr == NULL) {
218221
rc = PYSQLITE_SQL_WRONG_TYPE;
219222
return rc;
220223
}
224+
sql_len = strlen(sql_cstr); /* XXXX */
221225

222226
rc = sqlite3_prepare(self->db,
223227
sql_cstr,

0 commit comments

Comments
 (0)