mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix parseargs converters to wchar
This commit is contained in:
parent
91b7c428d3
commit
30a37bf583
@ -59,17 +59,12 @@ update_data(Device *self, PyObject *args) {
|
|||||||
// get_filesystem() {{{
|
// get_filesystem() {{{
|
||||||
static PyObject*
|
static PyObject*
|
||||||
py_get_filesystem(Device *self, PyObject *args) {
|
py_get_filesystem(Device *self, PyObject *args) {
|
||||||
PyObject *storage_id, *ret, *callback;
|
PyObject *callback;
|
||||||
wchar_t *storage;
|
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; }
|
if (!PyCallable_Check(callback)) { PyErr_SetString(PyExc_TypeError, "callback is not a callable"); return NULL; }
|
||||||
storage = unicode_to_wchar(storage_id);
|
return wpd::get_filesystem(self->device, storage.ptr(), self->bulk_properties, callback);
|
||||||
if (storage == NULL) return NULL;
|
|
||||||
|
|
||||||
ret = wpd::get_filesystem(self->device, storage, self->bulk_properties, callback);
|
|
||||||
free(storage);
|
|
||||||
return ret;
|
|
||||||
} // }}}
|
} // }}}
|
||||||
|
|
||||||
// get_file() {{{
|
// get_file() {{{
|
||||||
|
@ -46,7 +46,7 @@ typedef generic_raii<PyObject*, python_object_destructor> pyobject_raii;
|
|||||||
|
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
py_to_wchar(PyObject *obj, wchar_raii *output) {
|
py_to_wchar(PyObject *obj, wchar_t **output) {
|
||||||
if (!PyUnicode_Check(obj)) {
|
if (!PyUnicode_Check(obj)) {
|
||||||
if (obj == Py_None) { return 1; }
|
if (obj == Py_None) { return 1; }
|
||||||
PyErr_SetString(PyExc_TypeError, "unicode object expected");
|
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);
|
wchar_t *buf = PyUnicode_AsWideCharString(obj, NULL);
|
||||||
if (!buf) { PyErr_NoMemory(); return 0; }
|
if (!buf) { PyErr_NoMemory(); return 0; }
|
||||||
output->attach(buf);
|
*output = buf;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
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)) {
|
if (!PyUnicode_Check(obj)) {
|
||||||
PyErr_SetString(PyExc_TypeError, "unicode object expected");
|
PyErr_SetString(PyExc_TypeError, "unicode object expected");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
wchar_t *buf = PyUnicode_AsWideCharString(obj, NULL);
|
wchar_t *buf = PyUnicode_AsWideCharString(obj, NULL);
|
||||||
if (!buf) { PyErr_NoMemory(); return 0; }
|
if (!buf) { PyErr_NoMemory(); return 0; }
|
||||||
output->attach(buf);
|
*output = buf;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user