Mercurial > cpython-lru_cache-weakref
diff Modules/_sqlite/cursor.c @ 41669:d12811decf94
Use AsCharBuffer to get C strings out of Python strings.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 09 May 2007 23:37:01 +0000 |
| parents | 47f9efdc0855 |
| children | ffb1ae7233a2 |
line wrap: on
line diff
--- a/Modules/_sqlite/cursor.c Wed May 09 23:36:14 2007 +0000 +++ b/Modules/_sqlite/cursor.c Wed May 09 23:37:01 2007 +0000 @@ -409,8 +409,8 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* args) { PyObject* operation; - PyObject* operation_bytestr = NULL; - char* operation_cstr; + const char* operation_cstr; + Py_ssize_t operation_len; PyObject* parameters_list = NULL; PyObject* parameters_iter = NULL; PyObject* parameters = NULL; @@ -495,16 +495,8 @@ rc = pysqlite_statement_reset(self->statement); } - if (PyString_Check(operation)) { - operation_cstr = PyString_AsString(operation); - } else { - operation_bytestr = PyUnicode_AsUTF8String(operation); - if (!operation_bytestr) { - goto error; - } - - operation_cstr = PyString_AsString(operation_bytestr); - } + if (PyObject_AsCharBuffer(operation, &operation_cstr, &operation_len) < 0) + goto error; /* reset description and rowcount */ Py_DECREF(self->description); @@ -714,7 +706,6 @@ } error: - Py_XDECREF(operation_bytestr); Py_XDECREF(parameters); Py_XDECREF(parameters_iter); Py_XDECREF(parameters_list);
