]> granicus.if.org Git - python/commitdiff
"Fix" a few places that were using PyObject_AsCharBuffer() to convert a string
authorGuido van Rossum <guido@python.org>
Wed, 29 Aug 2007 03:34:29 +0000 (03:34 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 29 Aug 2007 03:34:29 +0000 (03:34 +0000)
(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.

Modules/_sqlite/cursor.c
Modules/_sqlite/statement.c

index 9c295a6944c45235253c45cf80ff0a0a646c73d3..55a1ffc834a08b13da2a404cedc78dfca8837d4b 100644 (file)
@@ -497,8 +497,10 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
         rc = pysqlite_statement_reset(self->statement);
     }
 
-    if (PyObject_AsCharBuffer(operation, &operation_cstr, &operation_len) < 0)
+    operation_cstr = PyUnicode_AsString(operation);
+    if (operation == NULL)
         goto error;
+    operation_len = strlen(operation_cstr); /* XXX */
 
     /* reset description and rowcount */
     Py_DECREF(self->description);
index b80b955847ae63f3b1daebce7916582070d5eb6f..a5801d69282aafa0e29e1840a7bd5f50c1f22a13 100644 (file)
@@ -50,10 +50,12 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con
     self->st = NULL;
     self->in_use = 0;
 
-    if (PyObject_AsCharBuffer(sql, &sql_cstr, &sql_cstr_len) < 0) {
+    sql_cstr = PyUnicode_AsString(sql);
+    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);
@@ -214,10 +216,12 @@ int pysqlite_statement_recompile(pysqlite_Statement* self, PyObject* params)
     Py_ssize_t sql_len;
     sqlite3_stmt* new_st;
 
-    if (PyObject_AsCharBuffer(self->sql, &sql_cstr, &sql_len) < 0) {
+    sql_cstr = PyUnicode_AsString(self->sql);
+    if (sql_cstr == NULL) {
         rc = PYSQLITE_SQL_WRONG_TYPE;
         return rc;
     }
+    sql_len = strlen(sql_cstr); /* XXXX */
 
     rc = sqlite3_prepare(self->db,
                          sql_cstr,