mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
DRYer
This commit is contained in:
parent
51d37960b1
commit
ad3f147c56
@ -502,7 +502,7 @@ get_files_and_folders(unsigned int level, IPortableDevice *device, CComPtr<IPort
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (Py_ssize_t i = 0; i < PyList_GET_SIZE(subfolders.ptr()); i++) {
|
for (Py_ssize_t i = 0; i < PyList_GET_SIZE(subfolders.ptr()); i++) {
|
||||||
wchar_raii child_id(PyList_GET_ITEM(subfolders.ptr(), i));
|
wchar_raii child_id(PyUnicode_AsWideCharString(PyList_GET_ITEM(subfolders.ptr(), i), NULL));
|
||||||
if (!child_id) return false;
|
if (!child_id) return false;
|
||||||
if (!get_files_and_folders(level+1, device, content, bulk_properties, child_id.ptr(), callback, ans)) return false;
|
if (!get_files_and_folders(level+1, device, content, bulk_properties, child_id.ptr(), callback, ans)) return false;
|
||||||
}
|
}
|
||||||
|
@ -41,15 +41,7 @@ class generic_raii {
|
|||||||
explicit operator bool() const noexcept { return handle != null; }
|
explicit operator bool() const noexcept { return handle != null; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class wchar_raii : public generic_raii<wchar_t*, PyMem_Free> {
|
typedef generic_raii<wchar_t*, PyMem_Free> wchar_raii;
|
||||||
public:
|
|
||||||
explicit wchar_raii() noexcept { handle = NULL; }
|
|
||||||
explicit wchar_raii(wchar_t *h) noexcept { handle = h; }
|
|
||||||
explicit wchar_raii(PyObject *unicode_object) noexcept {
|
|
||||||
if (!unicode_object || !PyUnicode_Check(unicode_object)) { handle = NULL; PyErr_SetString(PyExc_TypeError, "Not a unicode object"); }
|
|
||||||
else handle = PyUnicode_AsWideCharString(unicode_object, NULL);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
static inline void python_object_destructor(void *p) { PyObject *x = reinterpret_cast<PyObject*>(p); Py_XDECREF(x); }
|
static inline void python_object_destructor(void *p) { PyObject *x = reinterpret_cast<PyObject*>(p); Py_XDECREF(x); }
|
||||||
typedef generic_raii<PyObject*, python_object_destructor> pyobject_raii;
|
typedef generic_raii<PyObject*, python_object_destructor> pyobject_raii;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user