diff --git a/src/calibre/devices/mtp/windows/device.cpp b/src/calibre/devices/mtp/windows/device.cpp index b55592eead..2389ac7dec 100644 --- a/src/calibre/devices/mtp/windows/device.cpp +++ b/src/calibre/devices/mtp/windows/device.cpp @@ -59,17 +59,12 @@ update_data(Device *self, PyObject *args) { // get_filesystem() {{{ static PyObject* py_get_filesystem(Device *self, PyObject *args) { - PyObject *storage_id, *ret, *callback; - wchar_t *storage; + PyObject *callback; + wchar_raii storage; - if (!PyArg_ParseTuple(args, "OO", &storage_id, &callback)) return NULL; + if (!PyArg_ParseTuple(args, "O&O", py_to_wchar_no_none, &storage, &callback)) return NULL; if (!PyCallable_Check(callback)) { PyErr_SetString(PyExc_TypeError, "callback is not a callable"); return NULL; } - storage = unicode_to_wchar(storage_id); - if (storage == NULL) return NULL; - - ret = wpd::get_filesystem(self->device, storage, self->bulk_properties, callback); - free(storage); - return ret; + return wpd::get_filesystem(self->device, storage.ptr(), self->bulk_properties, callback); } // }}} // get_file() {{{ diff --git a/src/calibre/utils/cpp_binding.h b/src/calibre/utils/cpp_binding.h index 76f5f14508..f59eb66cfb 100644 --- a/src/calibre/utils/cpp_binding.h +++ b/src/calibre/utils/cpp_binding.h @@ -46,7 +46,7 @@ typedef generic_raii pyobject_raii; static inline int -py_to_wchar(PyObject *obj, wchar_raii *output) { +py_to_wchar(PyObject *obj, wchar_t **output) { if (!PyUnicode_Check(obj)) { if (obj == Py_None) { return 1; } PyErr_SetString(PyExc_TypeError, "unicode object expected"); @@ -54,18 +54,18 @@ py_to_wchar(PyObject *obj, wchar_raii *output) { } wchar_t *buf = PyUnicode_AsWideCharString(obj, NULL); if (!buf) { PyErr_NoMemory(); return 0; } - output->attach(buf); + *output = buf; return 1; } static inline int -py_to_wchar_no_none(PyObject *obj, wchar_raii *output) { +py_to_wchar_no_none(PyObject *obj, wchar_t **output) { if (!PyUnicode_Check(obj)) { PyErr_SetString(PyExc_TypeError, "unicode object expected"); return 0; } wchar_t *buf = PyUnicode_AsWideCharString(obj, NULL); if (!buf) { PyErr_NoMemory(); return 0; } - output->attach(buf); + *output = buf; return 1; }