diff Modules/_sqlite/statement.c @ 42984:3a56e73ae919

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).
author Guido van Rossum <guido@python.org>
date Wed, 29 Aug 2007 13:53:23 +0000
parents cb5ae020a060
children 8c10aac37037
line wrap: on
line diff
--- a/Modules/_sqlite/statement.c	Wed Aug 29 13:35:11 2007 +0000
+++ b/Modules/_sqlite/statement.c	Wed Aug 29 13:53:23 2007 +0000
@@ -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,