mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
On second thoughts overload & is too magical
This commit is contained in:
parent
55f52e0e09
commit
272ca315ea
@ -254,7 +254,7 @@ get_device_information(CComPtr<IPortableDevice> &device, CComPtr<IPortableDevice
|
||||
|
||||
#define S(what, key) { \
|
||||
com_wchar_raii temp; \
|
||||
if (SUCCEEDED(values->GetStringValue(what, &temp))) { \
|
||||
if (SUCCEEDED(values->GetStringValue(what, temp.unsafe_address()))) { \
|
||||
pyobject_raii t(PyUnicode_FromWideChar(temp.ptr(), -1)); \
|
||||
if (t) if (PyDict_SetItemString(ans, key, t.ptr()) != 0) PyErr_Clear(); \
|
||||
}}
|
||||
@ -305,9 +305,9 @@ get_device_information(CComPtr<IPortableDevice> &device, CComPtr<IPortableDevice
|
||||
pyobject_raii storage(get_storage_info(device));
|
||||
if (!storage) {
|
||||
pyobject_raii exc_type, exc_value, exc_tb;
|
||||
PyErr_Fetch(&exc_type, &exc_value, &exc_tb);
|
||||
PyErr_Fetch(exc_type.unsafe_address(), exc_value.unsafe_address(), exc_tb.unsafe_address());
|
||||
if (exc_type) {
|
||||
PyErr_NormalizeException(&exc_type, &exc_value, &exc_tb);
|
||||
PyErr_NormalizeException(exc_type.unsafe_address(), exc_value.unsafe_address(), exc_tb.unsafe_address());
|
||||
PyDict_SetItemString(ans, "storage_error", exc_value.ptr());
|
||||
} else {
|
||||
pyobject_raii t(PyUnicode_FromString("get_storage_info() failed without an error set"));
|
||||
|
@ -35,9 +35,8 @@ class generic_raii {
|
||||
T ptr() noexcept { return handle; }
|
||||
T detach() noexcept { T ans = handle; handle = null; return ans; }
|
||||
void attach(T val) noexcept { release(); handle = val; }
|
||||
T* address() noexcept { return &handle; }
|
||||
T* unsafe_address() noexcept { return &handle; }
|
||||
explicit operator bool() const noexcept { return handle != null; }
|
||||
T* operator &() noexcept { return &handle; }
|
||||
};
|
||||
|
||||
typedef generic_raii<wchar_t*, PyMem_Free> wchar_raii;
|
||||
@ -46,26 +45,26 @@ typedef generic_raii<PyObject*, python_object_destructor> pyobject_raii;
|
||||
|
||||
|
||||
static inline int
|
||||
py_to_wchar(PyObject *obj, wchar_t **output) {
|
||||
py_to_wchar(PyObject *obj, wchar_raii *output) {
|
||||
if (!PyUnicode_Check(obj)) {
|
||||
if (obj == Py_None) { *output = NULL; return 1; }
|
||||
if (obj == Py_None) { output->release(); return 1; }
|
||||
PyErr_SetString(PyExc_TypeError, "unicode object expected");
|
||||
return 0;
|
||||
}
|
||||
wchar_t *buf = PyUnicode_AsWideCharString(obj, NULL);
|
||||
if (!buf) { PyErr_NoMemory(); return 0; }
|
||||
*output = buf;
|
||||
output->attach(buf);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline int
|
||||
py_to_wchar_no_none(PyObject *obj, wchar_t **output) {
|
||||
py_to_wchar_no_none(PyObject *obj, wchar_raii *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 = buf;
|
||||
output->attach(buf);
|
||||
return 1;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user