Add PyUnicode_AsStringAndSize(), which is like PyUnicode_AsString() but
has an extra (optional) output parameter through which it returns the size.
Use this in a few places where I used PyUnicode_AsString() + strlen(),
and in one new place (which fixes test_pep263).
diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c
index a5801d6..b1a4e76 100644
--- a/Modules/_sqlite/statement.c
+++ b/Modules/_sqlite/statement.c
@@ -50,12 +50,11 @@
self->st = NULL;
self->in_use = 0;
- sql_cstr = PyUnicode_AsString(sql);
+ sql_cstr = PyUnicode_AsStringAndSize(sql, &sql_cstr_len);
if (sql_cstr == NULL) {
rc = PYSQLITE_SQL_WRONG_TYPE;
return rc;
}
- sql_cstr_len = strlen(sql_cstr); /* XXX */
self->in_weakreflist = NULL;
Py_INCREF(sql);
@@ -216,12 +215,11 @@
Py_ssize_t sql_len;
sqlite3_stmt* new_st;
- sql_cstr = PyUnicode_AsString(self->sql);
+ sql_cstr = PyUnicode_AsStringAndSize(self->sql, &sql_len);
if (sql_cstr == NULL) {
rc = PYSQLITE_SQL_WRONG_TYPE;
return rc;
}
- sql_len = strlen(sql_cstr); /* XXXX */
rc = sqlite3_prepare(self->db,
sql_cstr,